Do not apply minimum-should-match on a boolean query if the coords are disabled.

Fixes #15858
This commit is contained in:
Jim Ferenczi 2016-01-19 09:55:29 +01:00
parent b2baf039fd
commit 9b1daff9b5
3 changed files with 15 additions and 1 deletions

View File

@ -117,6 +117,9 @@ public class Queries {
if (minimumShouldMatch == null) {
return query;
}
if (query.isCoordDisabled()) {
return query;
}
int optionalClauses = 0;
for (BooleanClause c : query.clauses()) {
if (c.getOccur() == BooleanClause.Occur.SHOULD) {

View File

@ -272,6 +272,17 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
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 =
"{" +

View File

@ -288,7 +288,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
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) {