|
75 | 75 | import org.opensearch.index.query.QueryShardContext; |
76 | 76 | import org.opensearch.search.DocValueFormat; |
77 | 77 | import org.opensearch.search.MultiValueMode; |
| 78 | +import org.opensearch.search.approximate.ApproximatePointRangeQuery; |
| 79 | +import org.opensearch.search.approximate.ApproximateScoreQuery; |
78 | 80 | import org.opensearch.search.query.BitmapDocValuesQuery; |
79 | 81 | import org.opensearch.search.query.BitmapIndexQuery; |
80 | 82 | import org.junit.Before; |
|
96 | 98 | import static org.hamcrest.Matchers.either; |
97 | 99 | import static org.hamcrest.Matchers.equalTo; |
98 | 100 | import static org.hamcrest.Matchers.instanceOf; |
| 101 | +import static org.apache.lucene.document.LongPoint.pack; |
99 | 102 |
|
100 | 103 | public class NumberFieldTypeTests extends FieldTypeTestCase { |
101 | 104 |
|
@@ -392,9 +395,9 @@ public void testUnsignedLongRangeQueryWithDecimalParts() { |
392 | 395 |
|
393 | 396 | public void testLongRangeQuery() { |
394 | 397 | MappedFieldType ft = new NumberFieldMapper.NumberFieldType("field", NumberFieldMapper.NumberType.LONG); |
395 | | - Query expected = new IndexOrDocValuesQuery( |
396 | | - LongPoint.newRangeQuery("field", 1, 3), |
397 | | - SortedNumericDocValuesField.newSlowRangeQuery("field", 1, 3) |
| 398 | + Query expected = new ApproximateScoreQuery( |
| 399 | + new IndexOrDocValuesQuery(LongPoint.newRangeQuery("field", 1, 3), SortedNumericDocValuesField.newSlowRangeQuery("field", 1, 3)), |
| 400 | + new ApproximatePointRangeQuery("field", pack(1).bytes, pack(3).bytes, 1, ApproximatePointRangeQuery.LONG_FORMAT) |
398 | 401 | ); |
399 | 402 | assertEquals(expected, ft.rangeQuery("1", "3", true, true, null, null, null, MOCK_QSC)); |
400 | 403 |
|
@@ -681,7 +684,11 @@ public void doTestDocValueRangeQueries(NumberType type, Supplier<Number> valueSu |
681 | 684 | true, |
682 | 685 | MOCK_QSC |
683 | 686 | ); |
684 | | - assertThat(query, either(instanceOf(IndexOrDocValuesQuery.class)).or(instanceOf(MatchNoDocsQuery.class))); |
| 687 | + assertThat( |
| 688 | + query, |
| 689 | + either(instanceOf(IndexOrDocValuesQuery.class)).or(instanceOf(MatchNoDocsQuery.class)) |
| 690 | + .or(instanceOf(ApproximateScoreQuery.class)) |
| 691 | + ); |
685 | 692 | if (query instanceof IndexOrDocValuesQuery) { |
686 | 693 | IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) query; |
687 | 694 | assertEquals(searcher.count(indexOrDvQuery.getIndexQuery()), searcher.count(indexOrDvQuery.getRandomAccessQuery())); |
@@ -764,10 +771,20 @@ public void doTestIndexSortRangeQueries(NumberType type, Supplier<Number> valueS |
764 | 771 | true, |
765 | 772 | context |
766 | 773 | ); |
767 | | - assertThat(query, instanceOf(IndexSortSortedNumericDocValuesRangeQuery.class)); |
| 774 | + assertThat( |
| 775 | + query, |
| 776 | + either(instanceOf(IndexSortSortedNumericDocValuesRangeQuery.class)).or(instanceOf(ApproximateScoreQuery.class)) |
| 777 | + ); |
768 | 778 |
|
769 | | - Query fallbackQuery = ((IndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery(); |
770 | | - assertThat(fallbackQuery, instanceOf(IndexOrDocValuesQuery.class)); |
| 779 | + Query fallbackQuery; |
| 780 | + if (query instanceof IndexSortSortedNumericDocValuesRangeQuery) { |
| 781 | + fallbackQuery = ((IndexSortSortedNumericDocValuesRangeQuery) query).getFallbackQuery(); |
| 782 | + assertThat(fallbackQuery, instanceOf(IndexOrDocValuesQuery.class)); |
| 783 | + } else { |
| 784 | + fallbackQuery = ((IndexSortSortedNumericDocValuesRangeQuery) ((ApproximateScoreQuery) query).getOriginalQuery()) |
| 785 | + .getFallbackQuery(); |
| 786 | + assertThat(fallbackQuery, instanceOf(IndexOrDocValuesQuery.class)); |
| 787 | + } |
771 | 788 |
|
772 | 789 | IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) fallbackQuery; |
773 | 790 | assertEquals(searcher.count(query), searcher.count(indexOrDvQuery.getIndexQuery())); |
|
0 commit comments