lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Svensson <si...@devhost.se>
Subject Re: Including the index reader with top-docs
Date Tue, 18 Sep 2012 06:15:18 GMT
Hi,

I've always ended up using the Searcher.Search overload accepting a 
custom Collector, and do whatever magic required in Collector.Collect, 
where you have access to both an IndexReader and the documentId within 
that reader. You could use this to create new objects that hold this 
information, and use them after the search.

A very simple approach would be a DelagatingCollector.
https://github.com/devhost/Corelicious/blob/master/Corelicious.Lucene/DelagatingCollector.cs

   var hits = new List<Hit>();
   var collector = new DelegatingCollector((reader, doc, scorer) => {
     hits.Add(new Hit { Reader = reader, DocumentId = doc, Score = 
scorer.Score() });
   });
   searcher.Search(query, filter, collector);

   public class Hit {
     public IndexReader Reader { get; set; }
     public Int32 DocumentId { get; set; }
     public Single Score { get; set; }
   }

// Simon

On 2012-09-18 07:54, Patric Forsgard wrote:
> Hi
>
> If I'm  interested in the term frequency vector for my search result then I
> need to get my index reader to fetch that information without any problems.
> But if I using multisearcher I have problem to know which indexreader I
> should use. Is it possible to get the index reader together with the topdoc
> on some way?
>
> // Patric
>


Mime
View raw message