Improve Weight#count and IndexSearcher#count javadocs (#625)

This commit is contained in:
Luca Cavanna 2022-01-28 16:47:25 +01:00 committed by GitHub
parent 61edacee5d
commit 933c54fe87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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);

View File

@ -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.
*
* <p>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.
*
* <p>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
* <p>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
*
* <p>We use this property of the function to to count hits in {@link IndexSearcher#count(Query)}.
* <p>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.