shubhamvishu commented on code in PR #12183:
URL: https://github.com/apache/lucene/pull/12183#discussion_r1125496317


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -269,28 +273,55 @@ public String toString(String field) {
   @Override
   public final Query rewrite(IndexSearcher indexSearcher) throws IOException {
     final TermStates[] contexts = ArrayUtil.copyOfSubArray(this.contexts, 0, 
this.contexts.length);
-    for (int i = 0; i < contexts.length; ++i) {
-      if (contexts[i] == null
-          || contexts[i].wasBuiltFor(indexSearcher.getTopReaderContext()) == 
false) {
-        contexts[i] = TermStates.build(indexSearcher.getTopReaderContext(), 
terms[i], true);
-      }
-    }
-
-    // Compute aggregated doc freq and total term freq
-    // df will be the max of all doc freqs
-    // ttf will be the sum of all total term freqs
-    int df = 0;
-    long ttf = 0;
-    for (TermStates ctx : contexts) {
-      df = Math.max(df, ctx.docFreq());
-      ttf += ctx.totalTermFreq();
-    }
-
-    for (int i = 0; i < contexts.length; ++i) {
-      contexts[i] = adjustFrequencies(indexSearcher.getTopReaderContext(), 
contexts[i], df, ttf);
-    }
-
     Query[] termQueries = new Query[terms.length];
+    AtomicInteger index = new AtomicInteger(0);
+    AtomicInteger df = new AtomicInteger(0);
+    AtomicInteger ttf = new AtomicInteger(0);
+    Executor executor = 
Objects.requireNonNullElse(indexSearcher.getExecutor(), Runnable::run);
+    SliceExecutor sliceExecutor = new SliceExecutor(executor);
+    List<FutureTask<Object>> tasks =
+        Arrays.stream(contexts)
+            .map(
+                task ->
+                    new FutureTask<>(
+                        () -> {
+                          int i = index.getAndIncrement();
+                          if (contexts[i] == null
+                              || 
contexts[i].wasBuiltFor(indexSearcher.getTopReaderContext())
+                                  == false) {
+                            contexts[i] =
+                                TermStates.build(
+                                    indexSearcher.getTopReaderContext(), 
terms[i], true);
+                          }
+                          // Compute aggregated doc freq and total term freq
+                          // df will be the max of all doc freqs
+                          // ttf will be the sum of all total term freqs
+                          df.set(Math.max(df.get(), contexts[i].docFreq()));
+                          ttf.set((int) (ttf.get() + 
contexts[i].totalTermFreq()));

Review Comment:
   Thanks for flagging this @rmuir @uschindler. I'll change this in the next 
revision for avoid the race condition here. 



##########
lucene/core/src/java/org/apache/lucene/search/FieldExistsQuery.java:
##########
@@ -110,59 +116,91 @@ public int hashCode() {
   @Override
   public Query rewrite(IndexSearcher indexSearcher) throws IOException {
     IndexReader reader = indexSearcher.getIndexReader();
-    boolean allReadersRewritable = true;
+    final List<FutureTask<Boolean>> tasks =
+        reader.leaves().stream()
+            .map(
+                ctx ->
+                    new FutureTask<>(
+                        () -> {
+                          AtomicBoolean allReadersRewritable = new 
AtomicBoolean(true);
+                          LeafReader leaf = ctx.reader();
+                          FieldInfos fieldInfos = leaf.getFieldInfos();
+                          FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
+                          if (fieldInfo == null) {
+                            allReadersRewritable.set(false);
+                            return allReadersRewritable.get();
+                          }

Review Comment:
   Okay makes sense. I'll drop `FieldExistsQuery` in that case since that won't 
be beneficial at all.



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