|
55 | 55 | import org.apache.lucene.search.TermQuery;
|
56 | 56 | import org.apache.lucene.search.TopDocs;
|
57 | 57 | import org.apache.lucene.search.TotalHits;
|
| 58 | +import org.apache.lucene.search.TotalHits.Relation; |
58 | 59 | import org.apache.lucene.search.Weight;
|
59 | 60 | import org.apache.lucene.search.join.BitSetProducer;
|
60 | 61 | import org.apache.lucene.search.join.ScoreMode;
|
@@ -567,12 +568,13 @@ public void testTerminateAfterWithHitsNoHitCountShortcut() throws Exception {
|
567 | 568 | // size is lower than terminate_after
|
568 | 569 | context.setSize(5);
|
569 | 570 | // track_total_hits is lower than terminate_after
|
570 |
| - context.trackTotalHitsUpTo(randomIntBetween(1, 6)); |
| 571 | + int trackTotalHits = randomIntBetween(1, 6); |
| 572 | + context.trackTotalHitsUpTo(trackTotalHits); |
571 | 573 | QueryPhase.executeQuery(context);
|
572 | 574 | // depending on docs distribution we may or may not be able to honor terminate_after: low scoring hits are skipped via
|
573 | 575 | // setMinCompetitiveScore, which bypasses terminate_after until the next leaf collector is pulled, when that happens.
|
574 | 576 | assertThat(context.queryResult().terminatedEarly(), either(is(true)).or(is(false)));
|
575 |
| - assertThat(context.queryResult().topDocs().topDocs.totalHits.value(), equalTo(7L)); |
| 577 | + assertThat(context.queryResult().topDocs().topDocs.totalHits.value(), greaterThanOrEqualTo((long) trackTotalHits)); |
576 | 578 | assertThat(context.queryResult().topDocs().topDocs.totalHits.relation(), equalTo(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO));
|
577 | 579 | assertThat(context.queryResult().topDocs().topDocs.scoreDocs.length, equalTo(5));
|
578 | 580 | }
|
@@ -990,7 +992,10 @@ public void testMinScore() throws Exception {
|
990 | 992 | context.trackTotalHitsUpTo(5);
|
991 | 993 |
|
992 | 994 | QueryPhase.addCollectorsAndSearch(context);
|
993 |
| - assertEquals(10, context.queryResult().topDocs().topDocs.totalHits.value()); |
| 995 | + TotalHits totalHits = context.queryResult().topDocs().topDocs.totalHits; |
| 996 | + assertThat(totalHits.value(), greaterThanOrEqualTo(5L)); |
| 997 | + var expectedRelation = totalHits.value() == 10 ? Relation.EQUAL_TO : Relation.GREATER_THAN_OR_EQUAL_TO; |
| 998 | + assertThat(totalHits.relation(), is(expectedRelation)); |
994 | 999 | }
|
995 | 1000 | }
|
996 | 1001 |
|
|
0 commit comments