|
101 | 101 | import static org.hamcrest.Matchers.equalTo; |
102 | 102 | import static org.hamcrest.Matchers.greaterThan; |
103 | 103 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
104 | | -import static org.hamcrest.Matchers.in; |
105 | 104 | import static org.hamcrest.Matchers.instanceOf; |
106 | 105 | import static org.hamcrest.Matchers.is; |
| 106 | +import static org.hamcrest.Matchers.lessThan; |
107 | 107 | import static org.mockito.Mockito.mock; |
108 | 108 | import static org.mockito.Mockito.when; |
109 | 109 |
|
@@ -815,14 +815,8 @@ public void testNumericSortOptimization() throws Exception { |
815 | 815 | final SortAndFormats formatsLongDate = new SortAndFormats(sortLongDate, new DocValueFormat[] { DocValueFormat.RAW, dvFormatDate }); |
816 | 816 | final SortAndFormats formatsDateLong = new SortAndFormats(sortDateLong, new DocValueFormat[] { dvFormatDate, DocValueFormat.RAW }); |
817 | 817 |
|
818 | | - Query q = LongPoint.newRangeQuery(fieldNameLong, startLongValue, startLongValue + numDocs); |
819 | | - |
820 | | - // 0. test assertion - the query rewritten to a match all - https://github.com/apache/lucene/pull/14609/ |
821 | | - // TODO: reflow total hits expectations |
822 | | - try (TestSearchContext searchContext = createContext(newContextSearcher(reader), q)) { |
823 | | - var rewrittenQ = q.rewrite(searchContext.searcher()); |
824 | | - assertTrue(rewrittenQ instanceof MatchAllDocsQuery); |
825 | | - } |
| 818 | + // query all but one doc to avoid optimizations that may rewrite to a MatchAllDocs, which simplifies assertions |
| 819 | + Query q = LongPoint.newRangeQuery(fieldNameLong, startLongValue, startLongValue + numDocs - 2); |
826 | 820 |
|
827 | 821 | // 1. Test sort optimization on long field |
828 | 822 | try (TestSearchContext searchContext = createContext(newContextSearcher(reader), q)) { |
@@ -890,7 +884,7 @@ public void testNumericSortOptimization() throws Exception { |
890 | 884 | QueryPhase.addCollectorsAndSearch(searchContext); |
891 | 885 | assertTrue(searchContext.sort().sort.getSort()[0].getOptimizeSortWithPoints()); |
892 | 886 | assertThat(searchContext.queryResult().topDocs().topDocs.scoreDocs, arrayWithSize(0)); |
893 | | - assertThat(searchContext.queryResult().topDocs().topDocs.totalHits.value(), equalTo((long) numDocs)); |
| 887 | + assertThat(searchContext.queryResult().topDocs().topDocs.totalHits.value(), equalTo((long) numDocs - 1)); |
894 | 888 | assertThat(searchContext.queryResult().topDocs().topDocs.totalHits.relation(), equalTo(TotalHits.Relation.EQUAL_TO)); |
895 | 889 | } |
896 | 890 |
|
@@ -959,9 +953,8 @@ public void testMaxScoreQueryVisitor() { |
959 | 953 |
|
960 | 954 | // assert score docs are in order and their number is as expected |
961 | 955 | private static void assertSortResults(TopDocs topDocs, long totalNumDocs, boolean isDoubleSort) { |
962 | | - // TODO: fix java.lang.AssertionError: expected:<GREATER_THAN_OR_EQUAL_TO> but was:<EQUAL_TO> |
963 | | - // assertEquals(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO, topDocs.totalHits.relation()); |
964 | | - // assertThat(topDocs.totalHits.value(), lessThan(totalNumDocs)); // we collected less docs than total number |
| 956 | + assertEquals(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO, topDocs.totalHits.relation()); |
| 957 | + assertThat(topDocs.totalHits.value(), lessThan(totalNumDocs)); // we collected less docs than total number |
965 | 958 | long cur1, cur2; |
966 | 959 | long prev1 = Long.MIN_VALUE; |
967 | 960 | long prev2 = Long.MIN_VALUE; |
@@ -1002,11 +995,7 @@ public void testMinScore() throws Exception { |
1002 | 995 | QueryPhase.addCollectorsAndSearch(context); |
1003 | 996 | TotalHits totalHits = context.queryResult().topDocs().topDocs.totalHits; |
1004 | 997 | assertThat(totalHits.value(), greaterThanOrEqualTo(5L)); |
1005 | | - var expectedRelation = totalHits.value() == 10 ? Relation.EQUAL_TO : Relation.GREATER_THAN_OR_EQUAL_TO; |
1006 | | - // TODO: re assert expected total hits relation |
1007 | | - // var expectedRelation = totalHits.value() == 10 ? |
1008 | | - // Set.of(Relation.GREATER_THAN_OR_EQUAL_TO, Relation.EQUAL_TO) : Set.of(Relation.GREATER_THAN_OR_EQUAL_TO); |
1009 | | - // assertThat(totalHits.relation(), is(expectedRelation)); |
| 998 | + assertThat(totalHits.relation(), is(Relation.GREATER_THAN_OR_EQUAL_TO)); |
1010 | 999 | } |
1011 | 1000 | } |
1012 | 1001 |
|
|
0 commit comments