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
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>
  • Loading branch information
andrross authored and rayshrey committed Mar 18, 2024
1 parent ee6671a commit 438f403
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,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 438f403

Please sign in to comment.