lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: BitSet in a HitCollector
Date Thu, 06 Jul 2006 00:40:29 GMT

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

you don't need a BitSet in that case, you could find that out just using
an int...

    public CountingCollector extends HitCollector {
      public int count = 0;
      public void collect(int doc, float score) { count++ };
    }
    CountingCollector c = new CountingCollector();
    searcher.search(query, c)
    int numResults = c.count;

: 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();

This question doesn't make a lot of sense to me, why do you need to know
the total number ofresults before the collect method is called? .. what
you are suggesting here (using QueryFilter in this way) is perfectly
legal, but it's going to do just as much work as using a HitCollector will
(possibly more, i can't remember).

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

in your last example, you never us your HitCollector, so i'm not sure what
you mean, but assuming you aresking about combining those examples into
something like this....

  Searcher searcher = new IndexSearcher(indexReader);
  BitSet bits = (new QueryFilter(query)).bits(searcher.getIndexReader());
  final int numResults = bits.cardinality();
  searcher.search(query, new HitCollector() {
       public void collect(int doc, float score) {
          /* do something with numResults and doc and score */
       }
  });

...then yes, you are most definitely making two passes to do do that.



-Hoss


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