Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene pagination with TopScoreDocCollector

Tags:

lucene

I have a code like this with Lucene. Can someone provide a sample or tips about how to make the pagination with Lucene?

    Query q = queryParser.parse(useQuery);
TopScoreDocCollector collector = TopScoreDocCollector.create(maxReturn, true);
searcher.search(q, collector);

Thanks.

like image 478
user826323 Avatar asked Jun 28 '13 15:06

user826323


1 Answers

You can get the TopDocs representing a particular page of results, using TopDocsCollector.topDocs(int). Remember that the start argument represents how many documents in it should start, not how many "pages", so something like:

TopDocs hits = collector.topDocs(maxReturn*page);

Is usually appropriate (where page is numbered from 0)

like image 189
femtoRgon Avatar answered Sep 22 '22 10:09

femtoRgon