You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Philippe <ma...@gmail.com> on 2010/07/26 15:18:22 UTC
Fastest way to get number of matching documents
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;
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Fastest way to get number of matching documents
Posted by Philippe <ma...@gmail.com>.
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 <ma...@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
Re: Fastest way to get number of matching documents
Posted by Paul Libbrecht <pa...@activemath.org>.
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 <ma...@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
Re: Fastest way to get number of matching documents
Posted by Michael McCandless <lu...@mikemccandless.com>.
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.
Mike
On Mon, Jul 26, 2010 at 9:18 AM, Philippe <ma...@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;
>
> ---------------------------------------------------------------------
> 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