You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/08/16 02:01:49 UTC

[GitHub] [lucene] sonatype-lift[bot] commented on a change in pull request #242: LUCENE-9620 Add Weight#count(LeafReaderContext)

sonatype-lift[bot] commented on a change in pull request #242:
URL: https://github.com/apache/lucene/pull/242#discussion_r689196480



##########
File path: lucene/core/src/java/org/apache/lucene/search/Weight.java
##########
@@ -174,6 +174,27 @@ public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
     return new DefaultBulkScorer(scorer);
   }
 
+  /**
+   * Counts the number of documents that match a given {@link Weight#parentQuery} in a leaf. The
+   * default implementation creates a {@link TotalHitCountCollector} and scores it using a
+   * BulkScorer {@link Weight#bulkScorer(LeafReaderContext)}}. Specific query classes should
+   * override it to provide faster implementations. Look at {@link
+   * MatchAllDocsQuery#createWeight(IndexSearcher, ScoreMode, float)} for an example
+   *
+   * @param context the {@link org.apache.lucene.index.LeafReaderContext} for which to return the
+   *     count.
+   * @return integer count of the number of matches
+   * @throws IOException if there is a low-level I/O error
+   */
+  public int count(LeafReaderContext context) throws IOException {
+    TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
+    LeafCollector leafCollector = totalHitCountCollector.getLeafCollector(context);
+    // TODO: can we cache this bulkScorer call?
+    BulkScorer scorer = this.bulkScorer(context);
+    scorer.score(leafCollector, context.reader().getLiveDocs());

Review comment:
       *NULL_DEREFERENCE:*  object `scorer` last assigned on line 193 could be null and is dereferenced at line 194.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org