gautamworah96 commented on code in PR #12853:
URL: https://github.com/apache/lucene/pull/12853#discussion_r1421069686


##########
lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java:
##########
@@ -193,42 +204,29 @@ public BulkScorer bulkScorer(LeafReaderContext context) 
throws IOException {
           FacetsCollector sidewaysCollector = 
drillSidewaysCollectorManagers[dim].newCollector();
           sidewaysCollectors[dim] = sidewaysCollector;
 
-          dims[dim] = new DrillSidewaysScorer.DocsAndCost(scorer, 
sidewaysCollector);
+          dims[dim] =
+              new DrillSidewaysScorer.DocsAndCost(
+                  scorer, sidewaysCollector.getLeafCollector(context));
         }
 
-        // If more than one dim has no matches, then there
-        // are no hits nor drill-sideways counts.  Or, if we
-        // have only one dim and that dim has no matches,
-        // same thing.
-        // if (nullCount > 1 || (nullCount == 1 && dims.length == 1)) {
-        if (nullCount > 1) {
+        // If baseScorer is null or the dim nullCount > 1, then we have 
nothing to score. We return
+        // a null scorer in this case, but we need to make sure #finish gets 
called on all facet
+        // collectors since IndexSearcher won't handle this for us:
+        if (baseScorer == null || nullCount > 1) {
+          if (drillDownCollector != null) {
+            drillDownCollector.finish();
+          }
+          for (FacetsCollector fc : sidewaysCollectors) {
+            fc.finish();
+          }
           return null;
         }
 
         // Sort drill-downs by most restrictive first:
-        Arrays.sort(
-            dims,
-            new Comparator<DrillSidewaysScorer.DocsAndCost>() {
-              @Override
-              public int compare(DocsAndCost o1, DocsAndCost o2) {
-                return Long.compare(o1.approximation.cost(), 
o2.approximation.cost());
-              }
-            });
-
-        if (baseScorer == null) {
-          return null;
-        }
-
-        FacetsCollector drillDownCollector;
-        if (drillDownCollectorManager != null) {
-          drillDownCollector = drillDownCollectorManager.newCollector();
-          managedDrillDownCollectors.add(drillDownCollector);
-        } else {
-          drillDownCollector = null;
-        }
+        Arrays.sort(dims, Comparator.comparingLong(o -> 
o.approximation.cost()));

Review Comment:
   Thanks for these small cleanups as well. LGTM



##########
lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java:
##########
@@ -193,42 +204,29 @@ public BulkScorer bulkScorer(LeafReaderContext context) 
throws IOException {
           FacetsCollector sidewaysCollector = 
drillSidewaysCollectorManagers[dim].newCollector();
           sidewaysCollectors[dim] = sidewaysCollector;
 
-          dims[dim] = new DrillSidewaysScorer.DocsAndCost(scorer, 
sidewaysCollector);
+          dims[dim] =
+              new DrillSidewaysScorer.DocsAndCost(
+                  scorer, sidewaysCollector.getLeafCollector(context));
         }
 
-        // If more than one dim has no matches, then there
-        // are no hits nor drill-sideways counts.  Or, if we
-        // have only one dim and that dim has no matches,
-        // same thing.

Review Comment:
   unlrelated but how exactly is `(nullCount > 1 || (nullCount == 1 && 
dims.length == 1))` equivalent to `nullCount > 1`?



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