Skip to content

Commit

Permalink
Do not apply minimum-should-match on a boolean query if the coords ar…
Browse files Browse the repository at this point in the history
…e disabled.

Fixes #15858
  • Loading branch information
jimczi committed Jan 19, 2016
1 parent b2baf03 commit 9b1daff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Expand Up @@ -117,6 +117,9 @@ public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String
if (minimumShouldMatch == null) {
return query;
}
if (query.isCoordDisabled()) {
return query;

This comment has been minimized.

Copy link
@jpountz

jpountz Jan 19, 2016

Contributor

Could you leave a comment that disabled coords mean that this BQ is for synonyms?

This comment has been minimized.

Copy link
@jimczi

jimczi Jan 19, 2016

Author Contributor

Oups it's already merged. I'll commit directly in master.

This comment has been minimized.

Copy link
@jpountz

jpountz Jan 19, 2016

Contributor

Thanks.

}
int optionalClauses = 0;
for (BooleanClause c : query.clauses()) {
if (c.getOccur() == BooleanClause.Occur.SHOULD) {
Expand Down
Expand Up @@ -272,6 +272,17 @@ public void testMinShouldMatchBiggerThanNumberOfShouldClauses() throws Exception
assertEquals(3, bq.getMinimumNumberShouldMatch());
}

public void testMinShouldMatchDisableCoord() throws Exception {
BooleanQuery bq = (BooleanQuery) parseQuery(
boolQuery()
.should(termQuery("foo", "bar"))
.should(termQuery("foo2", "bar2"))
.minimumNumberShouldMatch("3")
.disableCoord(true)
.buildAsBytes()).toQuery(createShardContext());
assertEquals(0, bq.getMinimumNumberShouldMatch());
}

public void testFromJson() throws IOException {
String query =
"{" +
Expand Down
Expand Up @@ -288,7 +288,7 @@ protected void doAssertLuceneQuery(SimpleQueryStringBuilder queryBuilder, Query
Map.Entry<String, Float> field = fieldsIterator.next();
assertTermOrBoostQuery(booleanClause.getQuery(), field.getKey(), queryBuilder.value(), field.getValue());
}
if (queryBuilder.minimumShouldMatch() != null) {
if (queryBuilder.minimumShouldMatch() != null && !boolQuery.isCoordDisabled()) {
assertThat(boolQuery.getMinimumNumberShouldMatch(), greaterThan(0));
}
} else if (queryBuilder.fields().size() == 1) {
Expand Down

0 comments on commit 9b1daff

Please sign in to comment.