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: Getting count of documents matching a query?
Date Thu, 06 Apr 2006 22:19:03 GMT

: I need the count, and don't need the docs at this point. If I had a
: simple query, (e.g. "book") I can use docFreq(), and it's lightning
: fast. If I just run it as a query it's much slower. I'm just
: wondering if I did a custom scorer / similarity / hitcollector, how
: much faster than a query could I get it? Or is there a better way?

A custom HitCollector would be the first big win, something like this
would probably work...

   final int[] count = new int[1]
   searcher.search(query, new HitCollector() {
       public void collect(int doc, float score) {
          count[0]++;
       }
    });
    return count[0]

otherways you might be able to shave time would be...

  * if your query can be represented as in simple set logic logic (you
    don't seem to be concerned with score) then implimenting it as a
    Filter may be faster becuase it won't do any score calculation, just a
    simple match/no-match (which is what you seem to want) ... but it will
    definitely take up more memory then a query

  * if you customize your similarity so that every function returns 0 or 1
    you might shave a little bit of time off by skipping some of the math
    equations ... but i really doubt it.




-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