Skip to content

Commit

Permalink
Optimize UnsignedLong range queries to convert to MatchNoDocsQuery wh…
Browse files Browse the repository at this point in the history
…en lower > upper bounds (#14416)

* Added check for lower > upper at end of function

Signed-off-by: Skyring100 <[email protected]>

* Fixed mistake of using < operator on BigInteger, now using compareTo

Signed-off-by: Skyring100 <[email protected]>

* Fixed simple mistake of flipping > operator

Signed-off-by: Skyring100 <[email protected]>

* Fixed space formatting

Signed-off-by: Skyring100 <[email protected]>

* Updated CHANGELOG.md

Signed-off-by: Skyring100 <[email protected]>

* Issue number linked in CHANGELOG.md

Signed-off-by: Skyring100 <[email protected]>

* doTestDocValueRangeQueries now accepts MatchNoDocsQuery alongside IndexOrDocValuesQuery

Signed-off-by: Skyring100 <[email protected]>

* dotestdoTestDocValueRangeQueries only checks indexQuery and randomAccessQuery only when query is type IndexIndexOrDocValuesQuery

Signed-off-by: Skyring100 <[email protected]>

* Ran gradlew spotlessApply to fix import formatting issues

Signed-off-by: Skyring100 <[email protected]>

* Imported Matchers.either method instead of entire Matchers class

Signed-off-by: Skyring100 <[email protected]>

---------

Signed-off-by: Skyring100 <[email protected]>
Signed-off-by: Andriy Redko <[email protected]>
Co-authored-by: Andriy Redko <[email protected]>
  • Loading branch information
Skyring100 and reta committed Jun 21, 2024
1 parent a9d806a commit d8397c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,9 @@ public static Query unsignedLongRangeQuery(
u = u.subtract(BigInteger.ONE);
}
}
if (l.compareTo(u) > 0) {
return new MatchNoDocsQuery();
}
return builder.apply(l, u);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import java.util.function.Supplier;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;

Expand Down Expand Up @@ -673,9 +674,11 @@ public void doTestDocValueRangeQueries(NumberType type, Supplier<Number> valueSu
true,
MOCK_QSC
);
assertThat(query, instanceOf(IndexOrDocValuesQuery.class));
IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) query;
assertEquals(searcher.count(indexOrDvQuery.getIndexQuery()), searcher.count(indexOrDvQuery.getRandomAccessQuery()));
assertThat(query, either(instanceOf(IndexOrDocValuesQuery.class)).or(instanceOf(MatchNoDocsQuery.class)));
if (query instanceof IndexOrDocValuesQuery) {
IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) query;
assertEquals(searcher.count(indexOrDvQuery.getIndexQuery()), searcher.count(indexOrDvQuery.getRandomAccessQuery()));
}
}
reader.close();
dir.close();
Expand Down

0 comments on commit d8397c1

Please sign in to comment.