In recent Lucene versions there is an implementation of the mentioned collector to count hits, so there is no need to implement it: http://lucene.apache.org/java/3_4_0/api/core/org/apache/lucene/search/TotalHitCountCollector.html
Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: [email protected] > -----Original Message----- > From: Trejkaz [mailto:[email protected]] > Sent: Monday, September 19, 2011 8:10 AM > To: [email protected] > Subject: Re: Extracting all documents for a given search > > On Mon, Sep 19, 2011 at 3:50 AM, Charlie Hubbard > <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
