lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Libbrecht <p...@activemath.org>
Subject Re: Fastest way to get number of matching documents
Date Mon, 26 Jul 2010 14:25:43 GMT


Le 26-juil.-10 à 16:01, Michael McCandless a écrit :

> You can make a custom Collector?  Ie, it'd just increment a counter
> for each hit.
> As long as it does not call the Scorer.score() method then no  
> scoring is done.


I've done that.
Code below.

It feels a bit stupid to have to do that though. Sounds like a normal  
thing that should have been done already.

paul


> On Mon, Jul 26, 2010 at 9:18 AM, Philippe <mailer.thomas@gmail.com>  
> wrote:
>> Hi,
>>
>> for some queries I'm only interested in the number of matching  
>> documents. Is
>> there a better/faster way to perform such a query, instead of  
>> retrieving all
>> TopDocs and counting the number of totalHits [1]?
>> And is it possible/worthwhile to "deactivate" ranking?
>>
>> Cheers,
>>    Philippe
>>
>> [1]
>>        TopDocs td= is.search(query, is.maxDoc());
>>        int result= td.totalHits;


public class CounterHitCollector extends HitCollector {

     private int count=0;

     public void collect(int doc, float score) {
         count++;
     }

     public int getCount() {
         return count;
     }
}


---------------------------------------------------------------------
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