Apache Solr open-source search software
LUCENE-9566 TestApproximationSearchEquivalence.testExclusion fix (#1955)
Mayya Sharipova0b0894311223
diff --git a/lucene/core/src/java/org/apache/lucene/search/Weight.java b/lucene/core/src/java/org/apache/lucene/search/Weight.javaindex ba3755a5f4e..4d37fba4eff 100644--- a/lucene/core/src/java/org/apache/lucene/search/Weight.java+++ b/lucene/core/src/java/org/apache/lucene/search/Weight.java@@ -210,7 +210,7 @@ public abstract class Weight implements SegmentCacheable {} else {if (scorerIterator.docID() != -1) {// Wrap ScorerIterator to start from -1 for conjunction- scorerIterator = new RangeDISIWrapper(scorerIterator, max);+ scorerIterator = new StartDISIWrapper(scorerIterator);}// filter scorerIterator to keep only competitive docs as defined by collectorfilteredIterator = ConjunctionDISI.intersectIterators(Arrays.asList(scorerIterator, collectorIterator));@@ -277,16 +277,14 @@ public abstract class Weight implements SegmentCacheable {/*** Wraps an internal docIdSetIterator for it to start with docID = -1*/- protected static class RangeDISIWrapper extends DocIdSetIterator {+ protected static class StartDISIWrapper extends DocIdSetIterator {private final DocIdSetIterator in;private final int min;- private final int max;private int docID = -1;- public RangeDISIWrapper(DocIdSetIterator in, int max) {+ public StartDISIWrapper(DocIdSetIterator in) {this.in = in;this.min = in.docID();- this.max = max;}@Override@@ -301,16 +299,15 @@ public abstract class Weight implements SegmentCacheable {@Overridepublic int advance(int target) throws IOException {- target = Math.max(min, target);- if (target >= max) {- return docID = NO_MORE_DOCS;+ if (target <= min) {+ return docID = min;}return docID = in.advance(target);}@Overridepublic long cost() {- return Math.min(max - min, in.cost());+ return in.cost();}}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestApproximationSearchEquivalence.java b/lucene/core/src/test/org/apache/lucene/search/TestApproximationSearchEquivalence.javaindex 79c68bc3ea1..89fc12aa405 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestApproximationSearchEquivalence.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestApproximationSearchEquivalence.java@@ -196,7 +196,6 @@ public class TestApproximationSearchEquivalence extends SearchEquivalenceTestBasassertSameScores(bq1.build(), bq2.build());}- @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-9566")public void testExclusion() throws Exception {Term t1 = randomTerm();Term t2 = randomTerm();