Skip to content

Apache Lucene open-source search software

Advoid the use of ImpactsDISI when no minimum competitive score has been set (#13343)

zhongshanhao701c75a41232
diff --git a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java
index 04d01125146..aa276d277be 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java
@@ -56,9 +56,29 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
scorer1 = this.scorers[0];
scorer2 = this.scorers[1];
this.sumOfOtherClauses = new double[this.scorers.length];
+ for (int i = 0; i < sumOfOtherClauses.length; i++) {
+ sumOfOtherClauses[i] = Double.POSITIVE_INFINITY;
+ }
this.maxDoc = maxDoc;
}
+ private float computeMaxScore(int windowMin, int windowMax) throws IOException {
+ for (int i = 0; i < scorers.length; ++i) {
+ scorers[i].advanceShallow(windowMin);
+ }
+
+ float maxWindowScore = 0;
+ for (int i = 0; i < scorers.length; ++i) {
+ float maxClauseScore = scorers[i].getMaxScore(windowMax);
+ sumOfOtherClauses[i] = maxClauseScore;
+ maxWindowScore += maxClauseScore;
+ }
+ for (int i = sumOfOtherClauses.length - 2; i >= 0; --i) {
+ sumOfOtherClauses[i] += sumOfOtherClauses[i + 1];
+ }
+ return maxWindowScore;
+ }
+
@Override
public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException {
collector.setScorer(scorable);
@@ -68,20 +88,12 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
// Use impacts of the least costly scorer to compute windows
// NOTE: windowMax is inclusive
int windowMax = Math.min(scorers[0].advanceShallow(windowMin), max - 1);
- for (int i = 1; i < scorers.length; ++i) {
- scorers[i].advanceShallow(windowMin);
- }
- double maxWindowScore = 0;
- for (int i = 0; i < scorers.length; ++i) {
- double maxClauseScore = scorers[i].getMaxScore(windowMax);
- sumOfOtherClauses[i] = maxClauseScore;
- maxWindowScore += maxClauseScore;
- }
- for (int i = sumOfOtherClauses.length - 2; i >= 0; --i) {
- sumOfOtherClauses[i] += sumOfOtherClauses[i + 1];
+ float maxWindowScore = Float.POSITIVE_INFINITY;
+ if (0 < scorable.minCompetitiveScore) {
+ maxWindowScore = computeMaxScore(windowMin, windowMax);
}
- scoreWindow(collector, acceptDocs, windowMin, windowMax + 1, (float) maxWindowScore);
+ scoreWindow(collector, acceptDocs, windowMin, windowMax + 1, maxWindowScore);
windowMin = Math.max(lead1.docID(), windowMax + 1);
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java
index 127d6346edd..47ef5e07f19 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java
@@ -110,8 +110,13 @@ final class BlockMaxConjunctionScorer extends Scorer {
}
private void moveToNextBlock(int target) throws IOException {
- upTo = advanceShallow(target);
- maxScore = getMaxScore(upTo);
+ if (minScore == 0) {
+ upTo = target;
+ maxScore = Float.POSITIVE_INFINITY;
+ } else {
+ upTo = advanceShallow(target);
+ maxScore = getMaxScore(upTo);
+ }
}
private int advanceTarget(int target) throws IOException {