File tree 2 files changed +13
-3
lines changed
internalClusterTest/java/org/opensearch/search/simple
main/java/org/opensearch/search/approximate
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -439,8 +439,14 @@ public void testSimpleTerminateAfterTrackTotalHitsUpToRandomSize0() throws Excep
439
439
doTestSimpleTerminateAfterTrackTotalHitsUpTo (0 );
440
440
}
441
441
442
- public void testSimpleTerminateAfterTrackTotalHitsUpToSize () throws Exception {
443
- doTestSimpleTerminateAfterTrackTotalHitsUpTo (randomIntBetween (1 , 29 ));
442
+ // Tests scenario where size <= track_total_hits_up_to (5)
443
+ public void testSimpleTerminateAfterTrackTotalHitsUpToSmallSize () throws Exception {
444
+ doTestSimpleTerminateAfterTrackTotalHitsUpTo (randomIntBetween (1 , 5 ));
445
+ }
446
+
447
+ // Tests scenario where size > track_total_hits_up_to (5)
448
+ public void testSimpleTerminateAfterTrackTotalHitsUpToLargeSize () throws Exception {
449
+ doTestSimpleTerminateAfterTrackTotalHitsUpTo (randomIntBetween (6 , 29 ));
444
450
}
445
451
446
452
public void testSimpleIndexSortEarlyTerminate () throws Exception {
Original file line number Diff line number Diff line change @@ -449,7 +449,11 @@ public boolean canApproximate(SearchContext context) {
449
449
if (context .from () + context .size () == 0 ) {
450
450
this .setSize (SearchContext .DEFAULT_TRACK_TOTAL_HITS_UP_TO );
451
451
} else {
452
- this .setSize (Math .max (context .from () + context .size (), context .trackTotalHitsUpTo ()));
452
+ // We add +1 to ensure we collect at least one more document than required. This guarantees correct relation value:
453
+ // - If we find exactly trackTotalHitsUpTo docs: relation = EQUAL_TO
454
+ // - If we find > trackTotalHitsUpTo docs: relation = GREATER_THAN_OR_EQUAL_TO
455
+ // With +1, we will consistently get GREATER_THAN_OR_EQUAL_TO relation.
456
+ this .setSize (Math .max (context .from () + context .size (), context .trackTotalHitsUpTo ()) + 1 );
453
457
}
454
458
if (context .request () != null && context .request ().source () != null ) {
455
459
FieldSortBuilder primarySortField = FieldSortBuilder .getPrimaryFieldSortOrNull (context .request ().source ());
You can’t perform that action at this time.
0 commit comments