From 1d6543bef03c9da8fb747b26db41b9f98cb6be36 Mon Sep 17 00:00:00 2001 From: Andrew Ross Date: Thu, 16 Nov 2023 09:23:25 -0800 Subject: [PATCH] Fix SearchQueryIT to not depend on percentage 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 --- .../org/opensearch/search/query/SearchQueryIT.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java index d2bca41760ff6..c8e06f88da0e3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java @@ -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"));