If you pass reader.maxDoc(), it will create a heap (array) of size
reader.maxDoc() and is not recommended.
Instead, if you display the first page of results, you should pass 10
(assuming you display 10 results).
You can call TopFieldDocs.totalHits to get the total number of matching
results.

Then if you want to display the second page of results, pass 20, and take
results 11-20 and so on.

Does that help?

Shai

On Thu, Aug 6, 2009 at 12:59 PM, Savvas-Andreas Moysidis <
savvas.andreas.moysi...@googlemail.com> wrote:

> Hello,
>
> I'd like to ask if anybody has any thoughts on the best strategy to use
> when
> implementing a paging scenario in a Lucene search.
>
> In order to implement my paging list before the view is rendered I need to
> know the total number of documents this particular search would return but
> I
> still need to only load the documents of the specific page that has been
> requested.
>
> I'm thinking of using the search variant of :
>
> *TopFieldDocs search(Query query, Filter filter, int n,Sort sort);*
>
> since I need sorting and filtering and passing indeaxReader.maxDoc() for n.
> Will that create an array of size indeaxReader.maxDoc() ?
>
> After the search is finished I can retrieve only the documents I'm
> interested by using the sub-list of TopFieldDocs I've worked out.
>
> In the HitCollector docs :
>
>
> http://lucene.apache.org/java/2_4_1/api/org/apache/lucene/search/HitCollector.html
> I can see a way to use a BitSet but I'm not quite sure how this can be used
> to retrieve documents.
>
> Any alternatives/better ideas?
>
>
> thanks,
> Savvas
>

Reply via email to