Skip to content

Commit

Permalink
updating test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmpailis committed Sep 25, 2024
1 parent fd540aa commit 520df49
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.elasticsearch.search.retriever.rankdoc;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
Expand Down Expand Up @@ -124,7 +125,9 @@ public void testRankDocsQueryEarlyTerminate() throws IOException {
int numDocs = atLeast(20);
for (int i = 0; i < seg; i++) {
for (int j = 0; j < numDocs; j++) {
iw.addDocument(new Document());
Document doc = new Document();
doc.add(new NumericDocValuesField("active", 1));
iw.addDocument(doc);
}
if (frequently()) {
iw.flush();
Expand All @@ -145,10 +148,16 @@ public void testRankDocsQueryEarlyTerminate() throws IOException {
IndexSearcher searcher = new IndexSearcher(reader);
for (int totalHitsThreshold = 0; totalHitsThreshold < reader.maxDoc(); totalHitsThreshold += randomIntBetween(1, 10)) {
// Tests that the query matches only the {@link RankDoc} when the hit threshold is reached.
RankDocsQuery q = new RankDocsQuery(reader, rankDocs, new Query[] { new MatchAllDocsQuery() }, new String[1], false);
RankDocsQuery q = new RankDocsQuery(
reader,
rankDocs,
new Query[] { NumericDocValuesField.newSlowExactQuery("active", 1) },
new String[1],
false
);
var topDocsManager = new TopScoreDocCollectorManager(topSize, null, totalHitsThreshold);
var col = searcher.search(q, topDocsManager);
assertThat(col.totalHits.value, lessThanOrEqualTo((long) (Math.max(topSize, totalHitsThreshold) + topSize)));
assertThat(col.totalHits.value, lessThanOrEqualTo((long) (1 + Math.max(topSize, totalHitsThreshold) + topSize)));
assertEqualTopDocs(col.scoreDocs, rankDocs);
}

Expand Down

0 comments on commit 520df49

Please sign in to comment.