lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter W." <>
Subject Re: pagination
Date Thu, 22 Feb 2007 22:01:55 GMT

This snippet may help to understand TopDocs:

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  

You can also see my previous attempt at solving this:


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 []
> Sent: 21 February 2007 13:08
> To:
> 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 <> 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.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message