Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying for all results in Lucene IndexSearcher

Tags:

java

lucene

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

like image 768
Dan Q Avatar asked Oct 26 '11 08:10

Dan Q


2 Answers

If using a Lucene Reader, i.e. the IndexReader, you can help yourself by writing

TopDocs results = searcher.search(query, reader.numDocs());

This will ensure no result is omitted from the search.

like image 190
AGuyCalledGerald Avatar answered Nov 09 '22 18:11

AGuyCalledGerald


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

like image 29
L.B Avatar answered Nov 09 '22 17:11

L.B