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 Hirsch Laurence <La...@rhul.ac.uk> on 2006/11/27 14:30:18 UTC

Hits length with no sorting or scoring

Hello,

I have an application in which we only need to know the total number of
documents matching a query.  In this case we do not need any sorting or
scoring or to store any reference to the matching documents.  Can you
tell me how to execute such a query with maximum performance?

Thanks

Laurie

Re: Hits length with no sorting or scoring

Posted by Paul Elschot <pa...@xs4all.nl>.
On Monday 27 November 2006 14:30, Hirsch Laurence wrote:
> Hello,
> 
> I have an application in which we only need to know the total number of
> documents matching a query.  In this case we do not need any sorting or
> scoring or to store any reference to the matching documents.  Can you
> tell me how to execute such a query with maximum performance?

A fairly quick way is to implement your own HitCollector to count,
and then use the appropriate methods of IndexSearcher.

If you really need maximum performance, this bit of code
avoids computing the score values and invoking the
HitCollector (untested):

// s is the IndexSearcher, query the Query
org.apache.lucene.search.Scorer scorer =
   query.weight(s).scorer(s.getIndexReader());
int count = 0;
while (scorer.next()) count++;

Regards,
Paul Elschot


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