uschindler commented on code in PR #12183: URL: https://github.com/apache/lucene/pull/12183#discussion_r1125011860
########## 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: This is incorrect use of Atomic long. To really make atomic updates use methods like incrementAndGet or for more complex modifications in some atomic way use accumulateAndGet. -- 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