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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to