epotyom commented on code in PR #13568:
URL: https://github.com/apache/lucene/pull/13568#discussion_r1695011732


##########
lucene/facet/src/java/org/apache/lucene/facet/DrillSideways.java:
##########
@@ -398,130 +490,56 @@ private <R> ConcurrentDrillSidewaysResult<R> 
searchSequentially(
     }
     Query[] drillDownQueries = query.getDrillDownQueries();
 
-    int numDims = drillDownDims.size();
-
-    FacetsCollectorManager drillDownCollectorManager = 
createDrillDownFacetsCollectorManager();
-
-    FacetsCollectorManager[] drillSidewaysFacetsCollectorManagers =
-        new FacetsCollectorManager[numDims];
-    for (int i = 0; i < numDims; i++) {
-      drillSidewaysFacetsCollectorManagers[i] = 
createDrillSidewaysFacetsCollectorManager();
-    }
-
     DrillSidewaysQuery dsq =
         new DrillSidewaysQuery(
             baseQuery,
-            drillDownCollectorManager,
-            drillSidewaysFacetsCollectorManagers,
+            // drillDownCollectorOwner,
+            // Don't pass drill down collector because drill down is collected 
by IndexSearcher
+            // itself.
+            // TODO: deprecate drillDown collection in DrillSidewaysQuery?
+            null,
+            drillSidewaysCollectorOwners,
             drillDownQueries,
             scoreSubDocsAtOnce());
 
-    R collectorResult = searcher.search(dsq, hitCollectorManager);
-
-    FacetsCollector drillDownCollector;
-    if (drillDownCollectorManager != null) {
-      drillDownCollector = 
drillDownCollectorManager.reduce(dsq.managedDrillDownCollectors);
-    } else {
-      drillDownCollector = null;
-    }
-
-    FacetsCollector[] drillSidewaysCollectors = new FacetsCollector[numDims];
-    int numSlices = dsq.managedDrillSidewaysCollectors.size();
-
-    for (int dim = 0; dim < numDims; dim++) {
-      List<FacetsCollector> facetsCollectorsForDim = new 
ArrayList<>(numSlices);
-
-      for (int slice = 0; slice < numSlices; slice++) {
-        
facetsCollectorsForDim.add(dsq.managedDrillSidewaysCollectors.get(slice)[dim]);
-      }
-
-      drillSidewaysCollectors[dim] =
-          
drillSidewaysFacetsCollectorManagers[dim].reduce(facetsCollectorsForDim);
-    }
-
-    String[] drillSidewaysDims = drillDownDims.keySet().toArray(new String[0]);
-
-    return new ConcurrentDrillSidewaysResult<>(
-        buildFacetsResult(drillDownCollector, drillSidewaysCollectors, 
drillSidewaysDims),
-        null,
-        collectorResult,
-        drillDownCollector,
-        drillSidewaysCollectors,
-        drillSidewaysDims);
+    searcher.search(dsq, drillDownCollectorOwner);
   }
 
-  @SuppressWarnings("unchecked")
-  private <R> ConcurrentDrillSidewaysResult<R> searchConcurrently(
-      final DrillDownQuery query, final CollectorManager<?, R> 
hitCollectorManager)
+  private void searchConcurrently(
+      final DrillDownQuery query,
+      final CollectorOwner<?, ?> drillDownCollectorOwner,
+      final List<CollectorOwner<?, ?>> drillSidewaysCollectorOwners)
       throws IOException {
 
     final Map<String, Integer> drillDownDims = query.getDims();
     final List<CallableCollector> callableCollectors = new 
ArrayList<>(drillDownDims.size() + 1);
 
-    // Add the main DrillDownQuery
-    FacetsCollectorManager drillDownFacetsCollectorManager =
-        createDrillDownFacetsCollectorManager();
-    CollectorManager<?, ?> mainCollectorManager;
-    if (drillDownFacetsCollectorManager != null) {
-      // Make sure we populate a facet collector corresponding to the base 
query if desired:
-      mainCollectorManager =
-          new MultiCollectorManager(drillDownFacetsCollectorManager, 
hitCollectorManager);
-    } else {
-      mainCollectorManager = hitCollectorManager;
-    }
-    callableCollectors.add(new CallableCollector(-1, searcher, query, 
mainCollectorManager));
+    callableCollectors.add(new CallableCollector(-1, searcher, query, 
drillDownCollectorOwner));
     int i = 0;
     final Query[] filters = query.getDrillDownQueries();
-    for (String dim : drillDownDims.keySet())
+    for (String dim : drillDownDims.keySet()) {
       callableCollectors.add(
           new CallableCollector(
-              i++,
+              i,
               searcher,
               getDrillDownQuery(query, filters, dim),
-              createDrillSidewaysFacetsCollectorManager()));
-
-    final FacetsCollector mainFacetsCollector;
-    final FacetsCollector[] facetsCollectors = new 
FacetsCollector[drillDownDims.size()];
-    final R collectorResult;
+              drillSidewaysCollectorOwners.get(i)));
+      i++;
+    }
 
     try {
       // Run the query pool
-      final List<Future<CallableResult>> futures = 
executor.invokeAll(callableCollectors);
-
-      // Extract the results
-      if (drillDownFacetsCollectorManager != null) {
-        // If we populated a facets collector for the main query, make sure to 
unpack it properly
-        final Object[] mainResults = (Object[]) futures.get(0).get().result;
-        mainFacetsCollector = (FacetsCollector) mainResults[0];
-        collectorResult = (R) mainResults[1];
-      } else {
-        mainFacetsCollector = null;
-        collectorResult = (R) futures.get(0).get().result;
-      }
-      for (i = 1; i < futures.size(); i++) {
-        final CallableResult result = futures.get(i).get();
-        facetsCollectors[result.pos] = (FacetsCollector) result.result;
-      }
-      // Fill the null results with the mainFacetsCollector
-      for (i = 0; i < facetsCollectors.length; i++)
-        if (facetsCollectors[i] == null) facetsCollectors[i] = 
mainFacetsCollector;
+      final List<Future<Void>> futures = 
executor.invokeAll(callableCollectors);
 
+      // Wait for results. We don't read the results as they are collected by 
CollectorOwners
+      for (i = 0; i < futures.size(); i++) {
+        futures.get(0).get();

Review Comment:
   Oh, nice catch, thanks!



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