Skip to content

Commit 48016e0

Browse files
authored
fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when … (#14632)
* fix TestSortedDvMultiRangeQuery.testDuelWithStandardDisjunction when point occurs in the edge
1 parent 8d45ad6 commit 48016e0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lucene/sandbox/src/java/org/apache/lucene/sandbox/search/SortedNumericDocValuesMultiRangeQuery.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ private static NavigableSet<DocValuesMultiRangeQuery.LongRange> resolveOverlaps(
9595
new PriorityQueue<>(clauses.size() * 2) {
9696
@Override
9797
protected boolean lessThan(Edge a, Edge b) {
98-
return a.getValue() - b.getValue() < 0;
98+
if (a.getValue() < b.getValue()) {
99+
return true;
100+
} else if (a.getValue() == b.getValue()) {
101+
return a.point; // if a point is in the edge of the range, pass the point first
102+
} else {
103+
return false;
104+
}
99105
}
100106
};
101107
for (DocValuesMultiRangeQuery.LongRange r : clauses) {
@@ -115,7 +121,7 @@ protected boolean lessThan(Edge a, Edge b) {
115121
for (int i = 0; i < totalEdges; i++) {
116122
Edge smallest = heap.pop();
117123
if (depth == 0 && smallest.point) {
118-
if (i < totalEdges - 1 && heap.top().point) { // repeating same points
124+
if (i < totalEdges - 1) { // the point sits on the edge of the range
119125
if (smallest.getValue() == heap.top().getValue()) {
120126
continue;
121127
}
@@ -131,11 +137,13 @@ protected boolean lessThan(Edge a, Edge b) {
131137
} else {
132138
depth--;
133139
if (depth == 0) {
134-
sortedClauses.add(
140+
DocValuesMultiRangeQuery.LongRange range =
135141
started.range == smallest.range // no overlap case, the most often
136142
? smallest.range
137143
: new DocValuesMultiRangeQuery.LongRange(
138-
started.getValue(), smallest.getValue()));
144+
started.getValue(), smallest.getValue());
145+
boolean strictlyIncreasing = sortedClauses.add(range);
146+
assert strictlyIncreasing;
139147
started = null;
140148
}
141149
}

lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestSortedDvMultiRangeQuery.java

+11
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ private static DocValuesMultiRangeQuery.SortedNumericStabbingBuilder mrSNumDvBui
226226
int lower = ends[pos];
227227
int upper = ends[pos + 1];
228228
b.add(lower, upper);
229+
for (int repeat = 0; repeat < random().nextInt(3); repeat++) {
230+
if (rarely()) {
231+
b.add(lower, upper); // plain repeat
232+
} else {
233+
if (random().nextBoolean()) {
234+
b.add(lower, lower); // lower point repeat
235+
} else {
236+
b.add(upper, upper); // upper point repeat
237+
}
238+
}
239+
}
229240
}
230241
return b;
231242
}

0 commit comments

Comments
 (0)