Skip to content

Commit

Permalink
Fixing flakiness for ApproximatePointRangeQuery.testApproximateRangeS…
Browse files Browse the repository at this point in the history
…hortCircuitAscSort by enforcing sorting behavior after collecting docIDs (#15727) (#15871)

(cherry picked from commit 7cb2bd0)

Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 1c82963 commit 37a7ca3
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.store.Directory;
Expand All @@ -26,6 +29,7 @@

import java.io.IOException;

import static java.util.Arrays.asList;
import static org.apache.lucene.document.LongPoint.pack;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -253,8 +257,7 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException {
for (int v = 0; v < dims; v++) {
scratch[v] = i;
}
doc.add(new LongPoint("point", scratch));
iw.addDocument(doc);
iw.addDocument(asList(new LongPoint("point", scratch[0]), new NumericDocValuesField("point", scratch[0])));
}
iw.flush();
iw.forceMerge(1);
Expand All @@ -277,8 +280,9 @@ protected String toString(int dimension, byte[] value) {
Query query = LongPoint.newRangeQuery("point", lower, upper);
;
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs topDocs = searcher.search(approximateQuery, 10);
TopDocs topDocs1 = searcher.search(query, 10);
Sort sort = new Sort(new SortField("point", SortField.Type.LONG));
TopDocs topDocs = searcher.search(approximateQuery, 10, sort);
TopDocs topDocs1 = searcher.search(query, 10, sort);

// since we short-circuit from the approx range at the end of size these will not be equal
assertNotEquals(topDocs.totalHits, topDocs1.totalHits);
Expand Down

0 comments on commit 37a7ca3

Please sign in to comment.