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:33 UTC

[lucene] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 933c54f  Improve Weight#count and IndexSearcher#count javadocs (#625)
933c54f is described below

commit 933c54fe87bc42904d2e4911507414e007ec1390
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.