You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2022/01/28 15:47:48 UTC
[lucene] branch branch_9x updated: Improve Weight#count and IndexSearcher#count javadocs (#625)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new e3b2efe Improve Weight#count and IndexSearcher#count javadocs (#625)
e3b2efe is described below
commit e3b2efe73ebe7ff2176a4e6b7d33b079e729448a
Author: Luca Cavanna <ja...@users.noreply.github.com>
AuthorDate: Fri Jan 28 16:47:25 2022 +0100
Improve Weight#count and IndexSearcher#count javadocs (#625)
---
.../core/src/java/org/apache/lucene/search/IndexSearcher.java | 6 +++++-
lucene/core/src/java/org/apache/lucene/search/Weight.java | 10 +++++-----
2 files changed, 10 insertions(+), 6 deletions(-)
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 c07d5e2..abb3e49 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 9866e54..1a81581 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.
*
* <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.