Skip to content

Commit 7969882

Browse files
Fix approximation regression
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent 3dd4b8e commit 7969882

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ public void visit(DocIdSetIterator iterator) throws IOException {
177177

178178
@Override
179179
public void visit(IntsRef ref) {
180-
for (int i = 0; i < ref.length; i++) {
181-
adder.add(ref.ints[ref.offset + i]);
182-
}
180+
adder.add(ref);
181+
docCount[0] += ref.length;
183182
}
184183

185184
@Override
@@ -293,63 +292,45 @@ public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poin
293292
}
294293
}
295294

296-
// custom intersect visitor to walk the right of tree
295+
// custom intersect visitor to walk the right of tree (from rightmost leaf going left)
297296
public void intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] docCount)
298297
throws IOException {
299298
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
300299
if (docCount[0] >= size) {
301300
return;
302301
}
303302
switch (r) {
304-
case CELL_OUTSIDE_QUERY:
305-
// This cell is fully outside the query shape: stop recursing
306-
break;
307-
308303
case CELL_INSIDE_QUERY:
309-
// If the cell is fully inside, we keep moving right as long as the point tree size is over our size requirement
310-
if (pointTree.size() > size && docCount[0] < size && moveRight(pointTree)) {
304+
case CELL_CROSSES_QUERY:
305+
if (pointTree.moveToChild() && docCount[0] < size) {
306+
while (pointTree.moveToSibling()) {
307+
}
308+
311309
intersectRight(visitor, pointTree, docCount);
310+
312311
pointTree.moveToParent();
313-
}
314-
// if point tree size is no longer over, we have to go back one level where it still was over and the intersect left
315-
else if (pointTree.size() <= size && docCount[0] < size) {
316-
pointTree.moveToParent();
317-
intersectLeft(visitor, pointTree, docCount);
318-
}
319-
// if we've reached leaf, it means out size is under the size of the leaf, we can just collect all docIDs
320-
else {
321-
// Leaf node; scan and filter all points in this block:
312+
322313
if (docCount[0] < size) {
323-
pointTree.visitDocIDs(visitor);
314+
pointTree.moveToChild();
315+
intersectRight(visitor, pointTree, docCount);
316+
pointTree.moveToParent();
324317
}
325-
}
326-
break;
327-
case CELL_CROSSES_QUERY:
328-
// If the cell is fully inside, we keep moving right as long as the point tree size is over our size requirement
329-
if (pointTree.size() > size && docCount[0] < size && moveRight(pointTree)) {
330-
intersectRight(visitor, pointTree, docCount);
331-
pointTree.moveToParent();
332-
}
333-
// if point tree size is no longer over, we have to go back one level where it still was over and the intersect left
334-
else if (pointTree.size() <= size && docCount[0] < size) {
335-
pointTree.moveToParent();
336-
intersectLeft(visitor, pointTree, docCount);
337-
}
338-
// if we've reached leaf, it means out size is under the size of the leaf, we can just collect all doc values
339-
else {
340-
// Leaf node; scan and filter all points in this block:
318+
} else {
341319
if (docCount[0] < size) {
342-
pointTree.visitDocValues(visitor);
320+
if (r == PointValues.Relation.CELL_INSIDE_QUERY) {
321+
pointTree.visitDocIDs(visitor);
322+
} else {
323+
pointTree.visitDocValues(visitor);
324+
}
343325
}
344326
}
345327
break;
328+
case CELL_OUTSIDE_QUERY:
329+
break;
346330
default:
347331
throw new IllegalArgumentException("Unreachable code");
348332
}
349-
}
350333

351-
public boolean moveRight(PointValues.PointTree pointTree) throws IOException {
352-
return pointTree.moveToChild() && pointTree.moveToSibling();
353334
}
354335

355336
@Override

0 commit comments

Comments
 (0)