lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trejkaz <trej...@trypticon.org>
Subject Re: Extracting all documents for a given search
Date Mon, 19 Sep 2011 06:09:37 GMT
On Mon, Sep 19, 2011 at 3:50 AM, Charlie Hubbard
<charlie.hubbard@gmail.com> wrote:
> Here was the prior API I was calling:
>
>        Hits hits = getSearcher().search( query, filter, sort );
>
> The new API:
>
>        TopDocs hits = getSearcher().search( query, filter, startDoc +
> length, sort );
>
> So the question is what new API can I use that allows me to extract all
> documents matching the query, sort, and filter in a efficient way?

How I do this:

    // 1. Figure out how many results there will be.
    class CountCollector extends Collector {
        int count;
        public void collect(int doc) {
            count++;
        }
        // ... other empty methods ...
    }
    CountCollector collector = new CountCollector();
    getSearcher().search(query, filter, collector);
    int hitCount = collector.count;

    // 2. Actually do the query.
    hits = getSearcher().search(query, filter, hitCount, sort);

It is a bit unfortunate that there is no equivalent to TopDocs which
can grow dynamically, but this way is still going to be faster than
Hits was, for larger result sets.

TX

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message