Skip to content

Commit

Permalink
Fix SearchQueryIT to not depend on percentage (opensearch-project#11233
Browse files Browse the repository at this point in the history
…) (opensearch-project#11243)

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.


(cherry picked from commit 3509500)

Signed-off-by: Andrew Ross <[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 b33981e commit 3cc2e54
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 3cc2e54

Please sign in to comment.