Skip to content

Commit

Permalink
Fix SearchQueryIT to not depend on percentage (#11233)
Browse files Browse the repository at this point in the history
The CommonTermsQuery tests in SearchQueryIT had one case that depended
on the default cutoff frequency percentage. A recent change for
concurrent search increased the number of deleted documents that could
be indexed in the "indexRandom" helper method, and it turns out the
cutoff percentage is calculated from a max docs value that includes
deleted docs. This change replaces the default percentage with an absolute
value (number of documents that must match) so it is no longer
susceptible to behavior change due to number of deleted documents.

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit 3509500)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Nov 16, 2023
1 parent 78cfce4 commit 05ef16b
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,19 @@ public void testCommonTermsQuery() throws Exception {
assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3"));

searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get();
// cutoff frequency of 1 makes all terms high frequency so the query gets rewritten as a
// conjunction of all terms (the lowFreqMinimumShouldMatch parameter is effectively ignored)
searchResponse = client().prepareSearch()
.setQuery(commonTermsQuery("field1", "the huge fox").cutoffFrequency(1).lowFreqMinimumShouldMatch("2"))
.get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("2"));

// cutoff frequency of 100 makes all terms low frequency, so lowFreqMinimumShouldMatch=3
// means all terms must match
searchResponse = client().prepareSearch()
.setQuery(commonTermsQuery("field1", "the huge fox").cutoffFrequency(100).lowFreqMinimumShouldMatch("3"))
.get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("2"));

Expand Down

0 comments on commit 05ef16b

Please sign in to comment.