From 4010e7e9a7148d66d5fb3699c5a042053efea1f4 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 14 Aug 2015 10:47:38 +0200 Subject: [PATCH] Java api: restore support for minimumShouldMatch and disableCoord in TermsQueryBuilder TermsQueryParser still parses those values although deprecated. These need to be present in the java api as well to get ready for the query refactoring, where the builders are the intermediate query format that we parse our json queries into. Whatever the parser supports need to be supported by the builder as well. Closes #12870 --- .../index/query/TermsQueryBuilder.java | 32 +++++++++++++++++++ .../index/query/TermsQueryParser.java | 3 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index 5cc13c7f6ff..9ffdb0c647e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -32,6 +32,10 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui private final Object values; + private String minimumShouldMatch; + + private Boolean disableCoord; + private String queryName; private String execution; @@ -125,6 +129,26 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui return this; } + /** + * Sets the minimum number of matches across the provided terms. Defaults to 1. + * @deprecated use [bool] query instead + */ + @Deprecated + public TermsQueryBuilder minimumShouldMatch(String minimumShouldMatch) { + this.minimumShouldMatch = minimumShouldMatch; + return this; + } + + /** + * Disables Similarity#coord(int,int) in scoring. Defaults to false. + * @deprecated use [bool] query instead + */ + @Deprecated + public TermsQueryBuilder disableCoord(boolean disableCoord) { + this.disableCoord = disableCoord; + return this; + } + /** * Sets the filter name for the filter that can be used when searching for matched_filters per hit. */ @@ -148,6 +172,14 @@ public class TermsQueryBuilder extends QueryBuilder implements BoostableQueryBui builder.field("execution", execution); } + if (minimumShouldMatch != null) { + builder.field("minimum_should_match", minimumShouldMatch); + } + + if (disableCoord != null) { + builder.field("disable_coord", disableCoord); + } + if (boost != -1) { builder.field("boost", boost); } diff --git a/core/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java b/core/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java index 09f578d4bfa..fa643892e45 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java +++ b/core/src/main/java/org/elasticsearch/index/query/TermsQueryParser.java @@ -51,6 +51,7 @@ public class TermsQueryParser implements QueryParser { public static final String NAME = "terms"; private static final ParseField MIN_SHOULD_MATCH_FIELD = new ParseField("min_match", "min_should_match").withAllDeprecated("Use [bool] query instead"); + private static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord").withAllDeprecated("Use [bool] query instead"); private Client client; @Deprecated @@ -149,7 +150,7 @@ public class TermsQueryParser implements QueryParser { minShouldMatch = parser.textOrNull(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); - } else if (("disable_coord").equals(currentFieldName) || ("disableCoord").equals(currentFieldName)) { + } else if (parseContext.parseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) { disableCoord = parser.booleanValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text();