korrekorre
korrekorre

Reputation: 1034

Combine multiple Lucene indexes, with docs in same structure, for querying with sorting

I'm using Lucene Index for indexing of a couple of repositorys in a Java application. I've 3 indexes that stores documents of the same structure (fields). One contains approximately 160.000 docs, the second 30.000 and third 40.000.

There is no problem right now with the querying or sorting of result when I'm querying against one at a time. But, I want to query them all 3 and have the combined result sorted in the specified order.

Is this possible at all?

Upvotes: 4

Views: 708

Answers (1)

Tareq Salah
Tareq Salah

Reputation: 3718

You can use multireader

IndexReader r1= IndexReader.open(...)
IndexReader r2= IndexReader.open(...)
MultiReader multiReader = new MultiReader(r1, r2);
IndexSearcher searcher = new IndexSearcher(multiReader);

for more details you can see this example

Upvotes: 7

Related Questions