Dan Q Dan Q - 1 month ago 16
Java Question

Querying for all results in Lucene IndexSearcher

I'm working with the SearchFiles class in Lucene's contrib/demo directory. Rather than search for results in paginated form, I want to be retrieve all documents that match the query. Is there a way to do this with the existing API (3.4)? It seems like all the search functions require an integer indicating the amount of hits to return.

The demo code looks like

TopDocs results = searcher.search(query, 5 * hitsPerPage);
ScoreDoc[] its = results.scoreDocs;


Which will only return a fixed number of results

L.B L.B
Answer

Write your own Collector and use it as searcher.Search(query, new MyCollector());

http://lucene.apache.org/java/3_4_0/api/core/org/apache/lucene/search/Collector.html

Comments