You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Patric Forsgard <pa...@tasteful.se> on 2012/09/18 07:54:12 UTC

Including the index reader with top-docs

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

Re: Including the index reader with top-docs

Posted by Simon Svensson <si...@devhost.se>.
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
>