Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.17] [Backport 2.x] Fix approximate pointrangequery tests #15708

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@
public void visit(int docID) {
// it is possible that size < 1024 and docCount < size but we will continue to count through all the 1024 docs
// and collect less, but it won't hurt performance
if (docCount[0] < size) {
adder.add(docID);
docCount[0]++;
if (docCount[0] >= size) {
return;
}
adder.add(docID);
docCount[0]++;
}

@Override
Expand Down Expand Up @@ -231,7 +232,7 @@
public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] docCount)
throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] > size) {
if (docCount[0] >= size) {
return;
}
switch (r) {
Expand Down Expand Up @@ -279,7 +280,7 @@
public void intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] docCount)
throws IOException {
PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
if (docCount[0] > size) {
if (docCount[0] >= size) {
return;
}
switch (r) {
Expand Down Expand Up @@ -435,6 +436,10 @@
if (!(context.query() instanceof ApproximateIndexOrDocValuesQuery)) {
return false;
}
// size 0 could be set for caching
if (context.from() + context.size() == 0) {
this.setSize(10_000);

Check warning on line 441 in server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L441 was not covered by tests
}
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
if (context.request() != null && context.request().source() != null) {
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public void testApproximateRangeWithSizeUnderDefault() throws IOException {
}
doc.add(new LongPoint("point", scratch));
iw.addDocument(doc);
if (i % 15 == 0) iw.flush();
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand Down Expand Up @@ -166,6 +166,7 @@ public void testApproximateRangeWithSizeOverDefault() throws IOException {
iw.addDocument(doc);
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand All @@ -183,7 +184,7 @@ protected String toString(int dimension, byte[] value) {
};
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs topDocs = searcher.search(approximateQuery, 11000);
assertEquals(topDocs.totalHits, new TotalHits(11001, TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO));
assertEquals(topDocs.totalHits, new TotalHits(11000, TotalHits.Relation.EQUAL_TO));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -210,6 +211,7 @@ public void testApproximateRangeShortCircuit() throws IOException {
if (i % 10 == 0) iw.flush();
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand Down Expand Up @@ -255,6 +257,7 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException {
iw.addDocument(doc);
}
iw.flush();
iw.forceMerge(1);
try (IndexReader reader = iw.getReader()) {
try {
long lower = 0;
Expand All @@ -281,12 +284,12 @@ protected String toString(int dimension, byte[] value) {
assertNotEquals(topDocs.totalHits, topDocs1.totalHits);
assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO));
assertEquals(topDocs1.totalHits, new TotalHits(21, TotalHits.Relation.EQUAL_TO));
assertEquals(topDocs.scoreDocs[0].doc, 0);
assertEquals(topDocs.scoreDocs[1].doc, 1);
assertEquals(topDocs.scoreDocs[2].doc, 2);
assertEquals(topDocs.scoreDocs[3].doc, 3);
assertEquals(topDocs.scoreDocs[4].doc, 4);
assertEquals(topDocs.scoreDocs[5].doc, 5);
assertEquals(topDocs.scoreDocs[0].doc, topDocs1.scoreDocs[0].doc);
assertEquals(topDocs.scoreDocs[1].doc, topDocs1.scoreDocs[1].doc);
assertEquals(topDocs.scoreDocs[2].doc, topDocs1.scoreDocs[2].doc);
assertEquals(topDocs.scoreDocs[3].doc, topDocs1.scoreDocs[3].doc);
assertEquals(topDocs.scoreDocs[4].doc, topDocs1.scoreDocs[4].doc);
assertEquals(topDocs.scoreDocs[5].doc, topDocs1.scoreDocs[5].doc);

} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Loading