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: fastest way to get raw hit count
Date Mon, 29 May 2006 21:27:12 GMT

: Scorer scorer =
:  query.weight(indexSearcher).scorer(indexSearcher.getIndexReader());

You'd need to rewrite the query first to be safe.

A slightly higher level API approach would be a HitCollector that just
counts the hits...

http://lucene.apache.org/java/docs/api/org/apache/lucene/search/HitCollector.html

   Searcher searcher = new IndexSearcher(indexReader);
   final int[] count = new int[0]; // use array container since need final
   searcher.search(query, new HitCollector() {
      public void collect(int doc, float score) {
         count[0]++;
      }
    });
    System.out.println("count of matches: " + count[0]):



-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