jpountz commented on code in PR #12382:
URL: https://github.com/apache/lucene/pull/12382#discussion_r1333138769


##########
lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import org.apache.lucene.search.Weight.DefaultBulkScorer;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.MathUtil;
+
+/**
+ * BulkScorer implementation of {@link BlockMaxConjunctionScorer} that focuses 
on top-level
+ * conjunctions over clauses that do not have two-phase iterators. Use a 
{@link DefaultBulkScorer}
+ * around a {@link BlockMaxConjunctionScorer} if you need two-phase support.
+ * Another difference with {@link BlockMaxConjunctionScorer} is that this 
scorer computes scores on
+ * the fly in order to be able to skip evaluating more clauses if the total 
score would be under the
+ * minimum competitive score anyway. This generally works well because 
computing a score is cheaper
+ * than
+ */
+final class BlockMaxConjunctionBulkScorer extends BulkScorer {
+
+  private final Scorer[] scorers;
+  private final DocIdSetIterator[] iterators;
+  private final DocIdSetIterator lead;
+  private final DocAndScore scorable = new DocAndScore();
+  private final double[] sumOfOtherClauses;
+
+  BlockMaxConjunctionBulkScorer(List<Scorer> scorers) throws IOException {
+    if (scorers.size() <= 1) {
+      throw new IllegalArgumentException("Expected 2 or more scorers, got " + 
scorers.size());
+    }
+    this.scorers = scorers.toArray(Scorer[]::new);
+    Arrays.sort(this.scorers, Comparator.comparingLong(scorer -> 
scorer.iterator().cost()));
+    this.iterators =
+        
Arrays.stream(this.scorers).map(Scorer::iterator).toArray(DocIdSetIterator[]::new);
+    lead = iterators[0];
+    this.sumOfOtherClauses = new double[this.scorers.length];
+  }
+
+  @Override
+  public int score(LeafCollector collector, Bits acceptDocs, int min, int max) 
throws IOException {
+    collector.setScorer(scorable);
+
+    int windowMin = Math.max(lead.docID(), min);
+    while (windowMin < max) {
+      // Use impacts of the least costly scorer to compute windows
+      // NOTE: windowMax is inclusive

Review Comment:
   This is correct.



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