Skip to content

Commit

Permalink
[Backport 2.x] Fix AbstractStringFieldDataTestCase tests to account f…
Browse files Browse the repository at this point in the history
…or TotalHits lower bound (#4867)

* Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound (#4270)

Fixes tests to account for TotalHits uncertainty as of Lucene 9.

Signed-off-by: Daniel Widdis <[email protected]>
(cherry picked from commit 4643620)

* Added CHANGELOG.

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
Co-authored-by: Daniel Widdis <[email protected]>
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2022
1 parent 4e0d0be commit 38287d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Segment Replication] Adding check to make sure checkpoint is not processed when a shard's shard routing is primary ([#4716](https://github.com/opensearch-project/OpenSearch/pull/4716))
- Disable merge on refresh in DiskThresholdDeciderIT ([#4828](https://github.com/opensearch-project/OpenSearch/pull/4828))
- Better plural stemmer than minimal_english ([#4738](https://github.com/opensearch-project/OpenSearch/pull/4738))
- Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound ([4867](https://github.com/opensearch-project/OpenSearch/pull/4867))

### Security

Expand Down
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,13 @@ 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(1000 <= topDocs.totalHits.value);
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 38287d8

Please sign in to comment.