lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Pine <general_n...@yahoo.com>
Subject BitSet in a HitCollector
Date Wed, 05 Jul 2006 18:07:19 GMT
Hey Everyone,

I'm using a HitCollector and would like to know the
total number of results that matched a given query.
Based on the JavaDoc, I this will do the trick:

Searcher searcher = new IndexSearcher(indexReader);
   final BitSet bits = new
BitSet(indexReader.maxDoc());
   searcher.search(query, new HitCollector() {
       public void collect(int doc, float score) {
         bits.set(doc);
       }
     });
int numResults = bits.cardinality();

If I want to know the total number of results inside
of the HitCollector, i.e. before the collect method
has ever been called, I think I could pass the Query
and Searcher objects into the HitCollector and do this
in its constructor:

BitSet bits = (new
QueryFilter(query)).bits(searcher.getIndexReader());
int numResults = bits.cardinality();

Is there a performance penalty using the QueryFilter?
Is Lucene executing another pass over the index in
order to populate the BitSet and then doing another
pass while calling the collect method? Thanx.

JAMES



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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