diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java index c07d5e28b0f..abb3e4996f0 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java @@ -440,7 +440,11 @@ public class IndexSearcher { } } - /** Count how many documents match the given query. */ + /** + * Count how many documents match the given query. May be faster than counting number of hits by + * collecting all matches, as the number of hits is retrieved from the index statistics when + * possible. + */ public int count(Query query) throws IOException { query = rewrite(query); final Weight weight = createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1); diff --git a/lucene/core/src/java/org/apache/lucene/search/Weight.java b/lucene/core/src/java/org/apache/lucene/search/Weight.java index 9866e548197..1a81581bf80 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Weight.java +++ b/lucene/core/src/java/org/apache/lucene/search/Weight.java @@ -178,13 +178,13 @@ public abstract class Weight implements SegmentCacheable { * Counts the number of live documents that match a given {@link Weight#parentQuery} in a leaf. * *

The default implementation returns -1 for every query. This indicates that the count could - * not be computed in O(1) time. + * not be computed in sub-linear time. * - *

Specific query classes should override it to provide other accurate O(1) implementations - * (that actually return the count). Look at {@link MatchAllDocsQuery#createWeight(IndexSearcher, - * ScoreMode, float)} for an example + *

Specific query classes should override it to provide other accurate sub-linear + * implementations (that actually return the count). Look at {@link + * MatchAllDocsQuery#createWeight(IndexSearcher, ScoreMode, float)} for an example * - *

We use this property of the function to to count hits in {@link IndexSearcher#count(Query)}. + *

We use this property of the function to count hits in {@link IndexSearcher#count(Query)}. * * @param context the {@link org.apache.lucene.index.LeafReaderContext} for which to return the * count.