gautamworah96 commented on a change in pull request #242:
URL: https://github.com/apache/lucene/pull/242#discussion_r689713492



##########
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:
       Added a commit to fix it: 91b77f1




-- 
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-unsubscr...@lucene.apache.org

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



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

Reply via email to