Skip to content

Commit dce24c8

Browse files
authored
Fix negative cost in some IntersectVisitor implementations after #14138 (#14150)
Introduced in #14138, we need to prevent negative scores when subtracting the added hits in LatLonPointDistanceQuery, SpatialQuery and PointRangeQuery.
1 parent a4434ca commit dce24c8

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void visit(IntsRef ref) {
280280
for (int i = 0; i < ref.length; i++) {
281281
result.clear(ref.ints[ref.offset + i]);
282282
}
283-
cost[0] = -ref.length;
283+
cost[0] = Math.max(0, cost[0] - ref.length);
284284
}
285285

286286
@Override

lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public void visit(IntsRef ref) {
677677
for (int i = 0; i < ref.length; i++) {
678678
result.clear(ref.ints[ref.offset + i]);
679679
}
680-
cost[0] -= ref.length;
680+
cost[0] = Math.max(0, cost[0] - ref.length);
681681
}
682682

683683
@Override

lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void visit(IntsRef ref) {
233233
for (int i = ref.offset; i < ref.offset + ref.length; i++) {
234234
result.clear(ref.ints[i]);
235235
}
236-
cost[0] -= ref.length;
236+
cost[0] = Math.max(0, cost[0] - ref.length);
237237
}
238238

239239
@Override

0 commit comments

Comments
 (0)