lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philippe <mailer.tho...@gmail.com>
Subject Re: Fastest way to get number of matching documents
Date Mon, 26 Jul 2010 15:05:55 GMT
Hi Paul,

thanks for the code. It is much faster than the implementation before.

Cheers,
     Philippe

Am 26.07.2010 16:25, schrieb Paul Libbrecht:
>
>
> 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
>
>


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