From 64addee691e87f1b694e9b7f0938b9b0e17fb48b Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 10 May 2012 13:53:46 +0300 Subject: [PATCH] Query String URI: Add `lenient` to the URI `q` parameters, closes #1937. --- .../index/query/QueryStringQueryBuilder.java | 14 ++++++++++++++ .../rest/action/search/RestSearchAction.java | 1 + 2 files changed, 15 insertions(+) diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index 54f45c25f38..d79346cc7e5 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -85,6 +85,8 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { private String minimumShouldMatch; + private Boolean lenient; + public QueryStringQueryBuilder(String queryString) { this.queryString = queryString; } @@ -279,6 +281,15 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { return this; } + /** + * Sets the query string parser to be lenient when parsing field values, defaults to the index + * setting and if not set, defaults to false. + */ + public QueryStringQueryBuilder lenient(Boolean lenient) { + this.lenient = lenient; + return this; + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(QueryStringQueryParser.NAME); @@ -351,6 +362,9 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder { if (quoteFieldSuffix != null) { builder.field("quote_field_suffix", quoteFieldSuffix); } + if (lenient != null) { + builder.field("lenient", lenient); + } builder.endObject(); } } diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 7173a9aa168..fe3e672b69a 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -154,6 +154,7 @@ public class RestSearchAction extends BaseRestHandler { queryBuilder.analyzer(request.param("analyzer")); queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false)); queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true)); + queryBuilder.lenient(request.paramAsBooleanOptional("lenient", null)); String defaultOperator = request.param("default_operator"); if (defaultOperator != null) { if ("OR".equals(defaultOperator)) {