Skip to content

Commit f1c4a51

Browse files
committed
fix test
1 parent e5a37db commit f1c4a51

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@
101101
import static org.hamcrest.Matchers.equalTo;
102102
import static org.hamcrest.Matchers.greaterThan;
103103
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
104-
import static org.hamcrest.Matchers.in;
105104
import static org.hamcrest.Matchers.instanceOf;
106105
import static org.hamcrest.Matchers.is;
106+
import static org.hamcrest.Matchers.lessThan;
107107
import static org.mockito.Mockito.mock;
108108
import static org.mockito.Mockito.when;
109109

@@ -815,14 +815,8 @@ public void testNumericSortOptimization() throws Exception {
815815
final SortAndFormats formatsLongDate = new SortAndFormats(sortLongDate, new DocValueFormat[] { DocValueFormat.RAW, dvFormatDate });
816816
final SortAndFormats formatsDateLong = new SortAndFormats(sortDateLong, new DocValueFormat[] { dvFormatDate, DocValueFormat.RAW });
817817

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);
826820

827821
// 1. Test sort optimization on long field
828822
try (TestSearchContext searchContext = createContext(newContextSearcher(reader), q)) {
@@ -890,7 +884,7 @@ public void testNumericSortOptimization() throws Exception {
890884
QueryPhase.addCollectorsAndSearch(searchContext);
891885
assertTrue(searchContext.sort().sort.getSort()[0].getOptimizeSortWithPoints());
892886
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));
894888
assertThat(searchContext.queryResult().topDocs().topDocs.totalHits.relation(), equalTo(TotalHits.Relation.EQUAL_TO));
895889
}
896890

@@ -959,9 +953,8 @@ public void testMaxScoreQueryVisitor() {
959953

960954
// assert score docs are in order and their number is as expected
961955
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
965958
long cur1, cur2;
966959
long prev1 = Long.MIN_VALUE;
967960
long prev2 = Long.MIN_VALUE;
@@ -1002,11 +995,7 @@ public void testMinScore() throws Exception {
1002995
QueryPhase.addCollectorsAndSearch(context);
1003996
TotalHits totalHits = context.queryResult().topDocs().topDocs.totalHits;
1004997
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));
1010999
}
10111000
}
10121001

0 commit comments

Comments
 (0)