lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trejkaz <trej...@trypticon.org>
Subject Re: How to get the index for a document after a search over multiple indexes
Date Tue, 14 Jun 2016 23:42:52 GMT
On Wed, Jun 15, 2016 at 6:08 AM, Mark Shapiro <mshapiro@palamida.com> wrote:
> private static IndexSearcher getSearcher( String[] indexDirs ) throws Exception {
>   IndexReader[] readers = new IndexReader[indexDirs.length];
>   FSDirectory[] directorys = new FSDirectory[indexDirs.length];
>
>   for ( int i = 0; i < indexDirs.length; ++i ) {
>     File file = new File( indexDirs[i] );
>     directorys[i] = ( bWindows ) ? new MMapDirectory( file ) : new NIOFSDirectory( file
);
>     directorys[i].setReadChunkSize( Integer.MAX_VALUE );
>     readers[i] = IndexReader.open( directorys[i], true );
>   }
>
>   MultiReader multiReader = new MultiReader( readers, true );
>   IndexSearcher searcher = new IndexSearcher( multiReader, executorService );  // ExecutorService
>   return searcher;
> }

OK, so if you want to retrieve the Document, you can call
document(int) on this multiReader and it will automatically take care
of retrieving it from the right underlying reader.

If you want to do it manually, you can keep around the IndexReader[]
and binary search on it to figure out which one contains the doc ID.
Or you can build an int[] of the starting doc IDs for each reader and
use ReaderUtil.subIndex to compute it probably more efficiently. This
is what composite readers use to do the same thing internally.

TX

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


Mime
View raw message