summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
diff options
context:
space:
mode:
authorLuca Cavanna <javanna@users.noreply.github.com>2016-04-05 15:38:53 +0200
committerLuca Cavanna <javanna@users.noreply.github.com>2016-04-05 15:38:53 +0200
commit67ccfc354e8e665144f5ac68cf8b3b1257fee619 (patch)
tree75abc9adb8829768d6e64d37255f1aab83400bfa /core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
parent84eacadd5130740759fb508de3f1e8ab6cba1448 (diff)
Switch to using ParseField to parse query names
* [TEST] check registered queries one by one in SearchModuleTests * Switch to using ParseField to parse query names If we have a deprecated query name, at the moment we don't have a way to log any deprecation warning nor fail when we are in strict mode. With this change we use ParseField, which will take care of the camel casing that we currently do manually (so that one day we can remove it more easily). This also means, that each query will have a unique preferred name, and all the other names are deprecated. Terms query "in" synonym is now formally deprecated, as well as fuzzy_match, match_fuzzy, match_phrase and match_phrase_prefix for match query, mlt for more_like_this and geo_bbox for geo_bounding_box. All these will be removed in 6.0. Every QueryParser holds now a ParseField constant called QUERY_NAME_FIELD that holds the name for it. The first name is the preferred one, all the others are deprecated. The first name is taken from the NAME constant already present in each query builder object, so that we somehow keep the serialization constant separated from ParseField. This change also allowed us to remove the names method from the QueryParser interface.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java')
-rw-r--r--core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java10
1 files changed, 5 insertions, 5 deletions
diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
index 242af5af05..8b09ba7204 100644
--- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java
@@ -79,7 +79,7 @@ import static org.elasticsearch.index.mapper.Uid.createUidAsBytes;
*/
public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQueryBuilder> {
- public static final String NAME = "mlt";
+ public static final String NAME = "more_like_this";
public static final int DEFAULT_MAX_QUERY_TERMS = XMoreLikeThis.DEFAULT_MAX_QUERY_TERMS;
public static final int DEFAULT_MIN_TERM_FREQ = XMoreLikeThis.DEFAULT_MIN_TERM_FREQ;
@@ -478,10 +478,10 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
public MoreLikeThisQueryBuilder(@Nullable String[] fields, @Nullable String[] likeTexts, @Nullable Item[] likeItems) {
// TODO we allow null here for the _all field, but this is forbidden in the parser. Re-check
if (fields != null && fields.length == 0) {
- throw new IllegalArgumentException("mlt query requires 'fields' to be specified");
+ throw new IllegalArgumentException(NAME + " query requires 'fields' to be specified");
}
if ((likeTexts == null || likeTexts.length == 0) && (likeItems == null || likeItems.length == 0)) {
- throw new IllegalArgumentException("mlt query requires either 'like' texts or items to be specified.");
+ throw new IllegalArgumentException(NAME + " query requires either 'like' texts or items to be specified.");
}
this.fields = fields;
this.likeTexts = Optional.ofNullable(likeTexts).orElse(Strings.EMPTY_ARRAY);
@@ -811,7 +811,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
if (moreLikeFields.isEmpty()) {
return null;
}
- mltQuery.setMoreLikeFields(moreLikeFields.toArray(Strings.EMPTY_ARRAY));
+ mltQuery.setMoreLikeFields(moreLikeFields.toArray(new String[moreLikeFields.size()]));
// handle like texts
if (likeTexts.length > 0) {
@@ -950,7 +950,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
uids.add(createUidAsBytes(item.type(), item.id()));
}
if (!uids.isEmpty()) {
- TermsQuery query = new TermsQuery(UidFieldMapper.NAME, uids.toArray(new BytesRef[0]));
+ TermsQuery query = new TermsQuery(UidFieldMapper.NAME, uids.toArray(new BytesRef[uids.size()]));
boolQuery.add(query, BooleanClause.Occur.MUST_NOT);
}
}