Remove getters and setters for "minimumNumberShouldMatch" in BoolQueryBuilder
Currently we have getters an setters for both "minimumNumberShouldMatch" and "minimumShouldMatch", which both access the same internal value (minimumShouldMatch). Since we only document the `minimum_should_match` parameter for the query DSL, I think we can deprecate the other getters and setters for 5.x and remove with 6.0, also deprecating the `minimum_number_should_match` query DSL parameter.
This commit is contained in:
parent
6ad5486e6b
commit
16d79842ac
|
@ -56,8 +56,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
private static final String SHOULD = "should";
|
||||
private static final String MUST = "must";
|
||||
private static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord");
|
||||
private static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
|
||||
private static final ParseField MINIMUM_NUMBER_SHOULD_MATCH = new ParseField("minimum_number_should_match");
|
||||
private static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match", "minimum_number_should_match");
|
||||
private static final ParseField ADJUST_PURE_NEGATIVE = new ParseField("adjust_pure_negative");
|
||||
|
||||
private final List<QueryBuilder> mustClauses = new ArrayList<>();
|
||||
|
@ -167,7 +166,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
* <tt>MUST</tt> clauses one or more <code>SHOULD</code> clauses must match a document
|
||||
* for the BooleanQuery to match. No <tt>null</tt> value allowed.
|
||||
*
|
||||
* @see #minimumNumberShouldMatch(int)
|
||||
* @see #minimumShouldMatch(int)
|
||||
*/
|
||||
public BoolQueryBuilder should(QueryBuilder queryBuilder) {
|
||||
if (queryBuilder == null) {
|
||||
|
@ -181,7 +180,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
* Gets the list of clauses that <b>should</b> be matched by the returned documents.
|
||||
*
|
||||
* @see #should(QueryBuilder)
|
||||
* @see #minimumNumberShouldMatch(int)
|
||||
* @see #minimumShouldMatch(int)
|
||||
*/
|
||||
public List<QueryBuilder> should() {
|
||||
return this.shouldClauses;
|
||||
|
@ -202,34 +201,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
return this.disableCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.
|
||||
* <p>
|
||||
* By default no optional clauses are necessary for a match
|
||||
* (unless there are no required clauses). If this method is used,
|
||||
* then the specified number of clauses is required.
|
||||
* <p>
|
||||
* Use of this method is totally independent of specifying that
|
||||
* any specific clauses are required (or prohibited). This number will
|
||||
* only be compared against the number of matching optional clauses.
|
||||
*
|
||||
* @param minimumNumberShouldMatch the number of optional clauses that must match
|
||||
*/
|
||||
public BoolQueryBuilder minimumNumberShouldMatch(int minimumNumberShouldMatch) {
|
||||
this.minimumShouldMatch = Integer.toString(minimumNumberShouldMatch);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.
|
||||
* @see BoolQueryBuilder#minimumNumberShouldMatch(int)
|
||||
*/
|
||||
public BoolQueryBuilder minimumNumberShouldMatch(String minimumNumberShouldMatch) {
|
||||
this.minimumShouldMatch = minimumNumberShouldMatch;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string representation of the minimumShouldMatch settings for this query
|
||||
*/
|
||||
|
@ -245,6 +216,14 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum should match as an integer value.
|
||||
*/
|
||||
public BoolQueryBuilder minimumShouldMatch(int minimumShouldMatch) {
|
||||
this.minimumShouldMatch = Integer.toString(minimumShouldMatch);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> iff this query builder has at least one should, must, must not or filter clause.
|
||||
* Otherwise <code>false</code>.
|
||||
|
@ -364,8 +343,6 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
|
||||
boost = parser.floatValue();
|
||||
} else if (MINIMUM_NUMBER_SHOULD_MATCH.match(currentFieldName)) {
|
||||
minimumShouldMatch = parser.textOrNull();
|
||||
} else if (ADJUST_PURE_NEGATIVE.match(currentFieldName)) {
|
||||
adjustPureNegative = parser.booleanValue();
|
||||
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
|
||||
|
@ -391,7 +368,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
|||
boolQuery.boost(boost);
|
||||
boolQuery.disableCoord(disableCoord);
|
||||
boolQuery.adjustPureNegative(adjustPureNegative);
|
||||
boolQuery.minimumNumberShouldMatch(minimumShouldMatch);
|
||||
boolQuery.minimumShouldMatch(minimumShouldMatch);
|
||||
boolQuery.queryName(queryName);
|
||||
return boolQuery;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
query.disableCoord(randomBoolean());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
query.minimumNumberShouldMatch(randomMinimumShouldMatch());
|
||||
query.minimumShouldMatch(randomMinimumShouldMatch());
|
||||
}
|
||||
int mustClauses = randomIntBetween(0, 3);
|
||||
for (int i = 0; i < mustClauses; i++) {
|
||||
|
@ -244,14 +244,14 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
boolQuery()
|
||||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch("3")).toQuery(createShardContext());
|
||||
.minimumShouldMatch("3")).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
|
||||
bq = (BooleanQuery) parseQuery(
|
||||
boolQuery()
|
||||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch(3)).toQuery(createShardContext());
|
||||
.minimumShouldMatch(3)).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
boolQuery()
|
||||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch("3")
|
||||
.minimumShouldMatch("3")
|
||||
.disableCoord(true)).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ public class MatchedQueriesIT extends ESIntegTestCase {
|
|||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(
|
||||
boolQuery()
|
||||
.minimumNumberShouldMatch(1)
|
||||
.minimumShouldMatch(1)
|
||||
.should(queryStringQuery("dolor").queryName("dolor"))
|
||||
.should(queryStringQuery("elit").queryName("elit"))
|
||||
)
|
||||
|
|
|
@ -941,7 +941,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.should(boolQuery()
|
||||
.should(termQuery("field1", "value1"))
|
||||
.should(termQuery("field1", "value2"))
|
||||
.minimumNumberShouldMatch(3));
|
||||
.minimumShouldMatch(3));
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertFirstHit(searchResponse, hasId("1"));
|
||||
|
@ -951,9 +951,9 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.should(boolQuery()
|
||||
.should(termQuery("field1", "value1"))
|
||||
.should(termQuery("field1", "value2"))
|
||||
.minimumNumberShouldMatch(1))
|
||||
.minimumShouldMatch(1))
|
||||
// Only one should clause is defined, returns no docs.
|
||||
.minimumNumberShouldMatch(2);
|
||||
.minimumShouldMatch(2);
|
||||
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
||||
assertHitCount(searchResponse, 0L);
|
||||
|
||||
|
@ -962,8 +962,8 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.should(boolQuery()
|
||||
.should(termQuery("field1", "value1"))
|
||||
.should(termQuery("field1", "value2"))
|
||||
.minimumNumberShouldMatch(3))
|
||||
.minimumNumberShouldMatch(1);
|
||||
.minimumShouldMatch(3))
|
||||
.minimumShouldMatch(1);
|
||||
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertFirstHit(searchResponse, hasId("1"));
|
||||
|
@ -973,7 +973,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.must(boolQuery()
|
||||
.should(termQuery("field1", "value1"))
|
||||
.should(termQuery("field1", "value2"))
|
||||
.minimumNumberShouldMatch(3));
|
||||
.minimumShouldMatch(3));
|
||||
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
||||
assertHitCount(searchResponse, 0L);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue