Hello,

This snippet may help to understand TopDocs:

http://mail-archives.apache.org/mod_mbox/lucene-general/200508.mbox/% [EMAIL PROTECTED]

Also, paging through Lucene results is 'do-it-yourself' exercise using
hits.length() until someone contributes a good implementation.

Oversimplifying, if you want 10 hits per page:

hitsperpage equals ten;

-if hits length is less than ten, you have one page
-else if hits length/hitsperpage modulos is 0, that's your pagecount
-else hits length/hitsperpage is your pagecount, modulos is for your last page

You will also need a variable to keep track of which page you are on and a static method which returns min/max values to be included in your iteration loop.

You can also see my previous attempt at solving this:

http://www.gossamer-threads.com/lists/lucene/java-user/43595

Regards,

Peter W.

On Feb 21, 2007, at 6:32 AM, Kainth, Sachin wrote:

I might be missing something because TopDocs seems to only be about
finding the relevancy of documents and HitCollector doesn't seem to be
relavent either.

-----Original Message-----
From: Erick Erickson [mailto:[EMAIL PROTECTED]
Sent: 21 February 2007 13:08
To: java-user@lucene.apache.org
Subject: Re: pagination

See TopDocs, HitCollector, etc. Don't iterate through a Hits objects to get docs beyond, say, 100 since it's designed to efficiently return the first 100 documents but re-executes the queries each 100 or so times you
advance to the next document.

Erick

On 2/21/07, Kainth, Sachin <[EMAIL PROTECTED]> wrote:

Hello,

I was wondering if Lucene provides any mechanism which helps in
pagination.  In other words is there a way to return the first 10 of
500 results and then the  next 10 and so on.

Reply via email to