Hello,

as you might know, I am pretty new to Lucene and integrating 2.9.1 right now
into my current ASP.NET MVC project. And it's really working like a charm.
(Thanks to Michael)

I am curious about if I've understood it right, how to do paging with
Lucene. I've implemented it like so:

        IndexSearcher searcher = Searcher;

      // Collect all resulting documents until selected page
        TopScoreDocCollector collector =
TopScoreDocCollector.create((pageIndex + 1) * pageSize, false);
      searcher.Search(query, collector);

        // Get documents for selected page
      TopDocs hits = collector.TopDocs(pageIndex * pageSize, pageSize);

So in case if someone selects one of the last pages of a huge result, Lucene
would go over a lot results, even that I just need 'pageSize' results, is
that right? What about the performance or memory usage? I took a sneak peek
into the Searcher code and believe to have seen that Lucene is creating a
que as big as documents to get. So in case of a totalhit-count of let's say
20000, a pageSize of 20 and selecting the last page (999), even that I
actually need just the 20 last documents, Lucene is getting (and even
allocating mememory for?) all 20000 resulting documents. Is that right?

In other terms, I want to do a MySQL-equivalent to SELECT [...] LIMIT
pageIndex * pageSize, pageSize.

Markus


Reply via email to