List Info

Thread: Hits length with no sorting or scoring




Hits length with no sorting or scoring
user name
2006-11-27 13:30:18
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
Hits length with no sorting or scoring
user name
2006-11-27 18:51:48
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-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )