zhaih commented on code in PR #12160:
URL: https://github.com/apache/lucene/pull/12160#discussion_r1113630957


##########
lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java:
##########
@@ -73,17 +76,41 @@ public Query rewrite(IndexSearcher indexSearcher) throws 
IOException {
               .build();
       Query rewritten = indexSearcher.rewrite(booleanQuery);
       filterWeight = indexSearcher.createWeight(rewritten, 
ScoreMode.COMPLETE_NO_SCORES, 1f);
+    } else {
+      filterWeight = null;
     }
 
-    for (LeafReaderContext ctx : reader.leaves()) {
-      TopDocs results = searchLeaf(ctx, filterWeight);
-      if (ctx.docBase > 0) {
-        for (ScoreDoc scoreDoc : results.scoreDocs) {
-          scoreDoc.doc += ctx.docBase;
-        }
-      }
-      perLeafResults[ctx.ord] = results;
-    }
+    TopDocs[] perLeafResults =
+        reader.leaves().stream()
+            .map(
+                ctx -> {
+                  Supplier<TopDocs> supplier =
+                      () -> {
+                        try {
+                          TopDocs results = searchLeaf(ctx, filterWeight);
+                          if (ctx.docBase > 0) {
+                            for (ScoreDoc scoreDoc : results.scoreDocs) {
+                              scoreDoc.doc += ctx.docBase;
+                            }
+                          }
+                          return results;
+                        } catch (Exception e) {
+                          throw new CompletionException(e);
+                        }
+                      };
+
+                  Executor executor = indexSearcher.getExecutor();
+                  if (executor == null) {
+                    return CompletableFuture.completedFuture(supplier.get());
+                  } else {
+                    return CompletableFuture.supplyAsync(supplier, executor);

Review Comment:
   In `IndexSearcher` we're using 
[`SliceExecutor`](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/search/SliceExecutor.java#L67)
 to make sure the main thread is also doing some work but not only wait for 
joining. 
   I think we can replicate the same logic here? (Since KNN search is likely to 
be slow so probably the main thread should do some work as well?)
   
   Maybe we can just use the `SliceExecutor` from `IndexSearcher` so that it 
might also kind of solving the load balancing problem?



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