lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antony Bowesman <...@teamware.com>
Subject Change to MultiReader
Date Fri, 12 Sep 2008 04:55:01 GMT
There was a message from Kirk Roberts, 18/4/2007 - MultiSearcher vs MultiReader

Grant mentioned the visibility of the readerIndex() method in MultiReader, but 
nothing seems ever came of it.

Is there any reason why the following could not be put into MultiReader? 
Something like this seems necessary when handling multiple indices to solve the 
BitSet caching issue I raised on the user thread.

It's slightly more efficient for a Filter implementation bits() method to know 
these reader numbers in the filter (as the doc id always seems to increment) 
rather than delegating back to the reader to resolve it each call.  However, it 
gives useful utility methods for doing so, and gives freedom to the underlying 
implementation in case that needs to change.

Antony

/** Fetches the IndexReader instance where the specified document exists
  *  @param  n the MultiReader document number
  *  @return the reader index
  */
public int readerIndex(int n) {    // find reader for doc n:
   return MultiSegmentReader.readerIndex(n, this.starts, this.subReaders.length);
}

/** Fetches the document number in the specified reader for the given document
     number.
  *  @param  i the reader index obtained from {@link #readerIndex(int)}
  *  @param  n the MultiReader document number
  *  @return the mapped document number
  */
public int id(int i, int n) {    // find true doc for doc n:
   return n - this.starts[i];
}

/** Fetches the document number in the specified reader for the given document
     number.
  *  @param  n the MultiReader document number
  *  @return the mapped document number
  */
public int id(int n) {    // find true doc for doc n:
   return n - this.starts[readerIndex(n)];
}



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message