List Info

Thread: fastest way to get raw hit count




fastest way to get raw hit count
user name
2006-05-29 13:54:47
hi all,
   
  is there a faster way to retrieve ONLY the count of
results for a query?
   
  lucene ranks (scores) the first batch of docs and sorts
them by rank, this is functionality i dont need in certain
queries and i assume, not doing this can return the count
faster then the hits.length()
   
  any ideas???
   
  thanks,,,

		
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from
your PC and save big.
fastest way to get raw hit count
user name
2006-05-29 17:28:27
On Monday 29 May 2006 15:54, zzzzz shalev wrote:
> hi all,
>    
>   is there a faster way to retrieve ONLY the count of
results for a query?
>    
>   lucene ranks (scores) the first batch of docs and
sorts them by rank, this 
is functionality i dont need in certain queries and i
assume, not doing this 
can return the count faster then the hits.length()

Untested:

Scorer scorer =
 query.weight(indexSearcher).scorer(indexSearcher.getIndexRe
ader());

int docCount = 0;
while (scorer.next()) docCount++;


Regards,
Paul Elschot

------------------------------------------------------------
---------
To unsubscribe, e-mail: java-user-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org

fastest way to get raw hit count
user name
2006-05-29 21:27:12
: Scorer scorer =
: 
query.weight(indexSearcher).scorer(indexSearcher.getIndexRea
der());

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/d
ocs/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-unsubscribelucene.apache.org
For additional commands, e-mail: java-user-helplucene.apache.org

[1-3]

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