Skip to content

Commit

Permalink
Fix tests to account for TotalHits uncertainty
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Aug 19, 2022
1 parent ee26e01 commit 0ec0651
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.search.join.QueryBitSetProducer;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
Expand Down Expand Up @@ -340,7 +341,12 @@ public void testSortMissing(boolean first, boolean reverse) throws IOException {
randomBoolean() ? numDocs : randomIntBetween(10, numDocs),
new Sort(sortField)
);
assertEquals(numDocs, topDocs.totalHits.value);
// As of Lucene 9.0.0, totalHits may be a lower bound
if (topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO) {
assertEquals(numDocs, topDocs.totalHits.value);
} else {
assertTrue(numDocs >= topDocs.totalHits.value);
}
BytesRef previousValue = first ? null : reverse ? UnicodeUtil.BIG_TERM : new BytesRef();
for (int i = 0; i < topDocs.scoreDocs.length; ++i) {
final String docValue = searcher.doc(topDocs.scoreDocs[i].doc).get("value");
Expand Down

0 comments on commit 0ec0651

Please sign in to comment.