lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: How do lucene IDs work with MultiReader and MultiSearcher?
Date Tue, 21 Jun 2005 14:13:27 GMT

On Jun 21, 2005, at 9:19 AM, Nick Burch wrote:

> Hi
> I've been scanning the JavaDocs, but I can't see anything on this.
> Let's say I have two indexes. Both have just been optimised, so  
> each have lucene IDs 1-10 in them.
> Now, I build a MultiSearcher over these two indexes. I search, get  
> back a Hits object, and from that a lucene ID
>> From my testing, it seems that the MultiSearcher has handily  
>> offset all
> the lucene IDs from the second index, so they don't clash with the  
> first. It also seems that if I pass that ID to a MultiReader built  
> on the same set of indexes, I get the right document back.
> (i.e. my hits object gives me a lucene ID of 5 for my first hit,  
> and if I ask the multireader for document with lucene ID 5, I get  
> the same document)
> Is this always going to be the case? Do I simply have to ensure  
> that I open the MultiReader and MultiSearcher with the indexes in  
> the right order to ensure the lucene IDs will be identically  
> munged, or is it trickier than that? uses MultiSearcher and hits from different indexes are  
handled differently.  Blog hits are shown fully.  Book section hits  
are shown as snippets.  Here's how it's done:

       MultiSearcher searcher = (MultiSearcher) context.getAttribute 
       IndexReader[] readers = (IndexReader[]) context.getAttribute 

       for (int i = startHit; i <= endHit; i++) {
         int position = i - 1;
         Document doc = hits.doc(position);
         int indexIndex = searcher.subSearcher(;
         IndexReader reader = readers[indexIndex];

         // ...

MulitSearcher handles the offsetting based on the specific IndexReader.

Look at the MultiSearcher API.  There is also a subDoc() method to  
get the document number for it's specific index.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message