javanna commented on code in PR #13603:
URL: https://github.com/apache/lucene/pull/13603#discussion_r1687837747


##########
lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java:
##########
@@ -694,40 +695,56 @@ protected void search(List<LeafReaderContext> leaves, 
Weight weight, Collector c
     // threaded...? the Collector could be sync'd?
     // always use single thread:
     for (LeafReaderContext ctx : leaves) { // search each subreader
-      final LeafCollector leafCollector;
+      searchLeaf(ctx, weight, collector);
+    }
+  }
+
+  /**
+   * Lower-level search API
+   *
+   * <p>{@link LeafCollector#collect(int)} is called for every document. <br>
+   *
+   * @param ctx the leaf to execute the search against
+   * @param weight to match document
+   * @param collector to receive hits
+   * @throws TooManyClauses If a query would exceed {@link 
IndexSearcher#getMaxClauseCount()}
+   *     clauses.
+   */
+  protected void searchLeaf(LeafReaderContext ctx, Weight weight, Collector 
collector)
+      throws IOException {
+    final LeafCollector leafCollector;
+    try {
+      leafCollector = collector.getLeafCollector(ctx);
+    } catch (
+        @SuppressWarnings("unused")
+        CollectionTerminatedException e) {
+      // there is no doc of interest in this reader context
+      // continue with the following leaf
+      return;
+    }
+    ScorerSupplier scorerSupplier = weight.scorerSupplier(ctx);
+    if (scorerSupplier != null) {
+      scorerSupplier.setTopLevelScoringClause();
+      BulkScorer scorer = scorerSupplier.bulkScorer();
+      if (queryTimeout != null) {
+        scorer = new TimeLimitingBulkScorer(scorer, queryTimeout);
+      }
       try {
-        leafCollector = collector.getLeafCollector(ctx);
+        scorer.score(leafCollector, ctx.reader().getLiveDocs());
       } catch (
           @SuppressWarnings("unused")
           CollectionTerminatedException e) {
-        // there is no doc of interest in this reader context
+        // collection was terminated prematurely
         // continue with the following leaf
-        continue;
-      }
-      ScorerSupplier scorerSupplier = weight.scorerSupplier(ctx);
-      if (scorerSupplier != null) {
-        scorerSupplier.setTopLevelScoringClause();
-        BulkScorer scorer = scorerSupplier.bulkScorer();
-        if (queryTimeout != null) {
-          scorer = new TimeLimitingBulkScorer(scorer, queryTimeout);
-        }
-        try {
-          scorer.score(leafCollector, ctx.reader().getLiveDocs());
-        } catch (
-            @SuppressWarnings("unused")
-            CollectionTerminatedException e) {
-          // collection was terminated prematurely
-          // continue with the following leaf
-        } catch (
-            @SuppressWarnings("unused")
-            TimeLimitingBulkScorer.TimeExceededException e) {
-          partialResult = true;
-        }
+      } catch (
+          @SuppressWarnings("unused")
+          TimeLimitingBulkScorer.TimeExceededException e) {
+        partialResult = true;
       }
-      // Note: this is called if collection ran successfully, including the 
above special cases of
-      // CollectionTerminatedException and TimeExceededException, but no other 
exception.
-      leafCollector.finish();
     }
+    // Note: this is called if collection ran successfully, including the 
above special cases of
+    // CollectionTerminatedException and TimeExceededException, but no other 
exception.
+    leafCollector.finish();

Review Comment:
   The diff is misleading: this is a pure cut and paste of the code from within 
the existing loop, to the new method that's called for every entry.



-- 
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