Query String URI: Add `lenient` to the URI `q` parameters, closes #1937.

This commit is contained in:
Shay Banon 2012-05-10 13:53:46 +03:00
parent cda633afee
commit 64addee691
2 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,8 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder {
private String minimumShouldMatch; private String minimumShouldMatch;
private Boolean lenient;
public QueryStringQueryBuilder(String queryString) { public QueryStringQueryBuilder(String queryString) {
this.queryString = queryString; this.queryString = queryString;
} }
@ -279,6 +281,15 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder {
return this; 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 @Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException { protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(QueryStringQueryParser.NAME); builder.startObject(QueryStringQueryParser.NAME);
@ -351,6 +362,9 @@ public class QueryStringQueryBuilder extends BaseQueryBuilder {
if (quoteFieldSuffix != null) { if (quoteFieldSuffix != null) {
builder.field("quote_field_suffix", quoteFieldSuffix); builder.field("quote_field_suffix", quoteFieldSuffix);
} }
if (lenient != null) {
builder.field("lenient", lenient);
}
builder.endObject(); builder.endObject();
} }
} }

View File

@ -154,6 +154,7 @@ public class RestSearchAction extends BaseRestHandler {
queryBuilder.analyzer(request.param("analyzer")); queryBuilder.analyzer(request.param("analyzer"));
queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false)); queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true)); queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
queryBuilder.lenient(request.paramAsBooleanOptional("lenient", null));
String defaultOperator = request.param("default_operator"); String defaultOperator = request.param("default_operator");
if (defaultOperator != null) { if (defaultOperator != null) {
if ("OR".equals(defaultOperator)) { if ("OR".equals(defaultOperator)) {