Skip to content

Commit

Permalink
Java api: add missing support for escape to QueryStringQueryBuilder
Browse files Browse the repository at this point in the history
QueryStringQueryParser parses `escape`, but java api users had no chance to actually set it.

Closes #13016
  • Loading branch information
javanna committed Aug 21, 2015
1 parent 09d4ea4 commit bce15d1
Showing 1 changed file with 15 additions and 3 deletions.
Expand Up @@ -68,7 +68,6 @@ public enum Operator {

private Locale locale;


private float boost = -1;

private Fuzziness fuzziness;
Expand Down Expand Up @@ -99,6 +98,8 @@ public enum Operator {
/** To limit effort spent determinizing regexp queries. */
private Integer maxDeterminizedStates;

private Boolean escape;

public QueryStringQueryBuilder(String queryString) {
this.queryString = queryString;
}
Expand Down Expand Up @@ -159,11 +160,11 @@ public QueryStringQueryBuilder tieBreaker(float tieBreaker) {
/**
* Sets the boolean operator of the query parser used to parse the query string.
* <p/>
* <p>In default mode ({@link FieldQueryBuilder.Operator#OR}) terms without any modifiers
* <p>In default mode ({@link Operator#OR}) terms without any modifiers
* are considered optional: for example <code>capital of Hungary</code> is equal to
* <code>capital OR of OR Hungary</code>.
* <p/>
* <p>In {@link FieldQueryBuilder.Operator#AND} mode terms are considered to be in conjunction: the
* <p>In {@link Operator#AND} mode terms are considered to be in conjunction: the
* above mentioned query is parsed as <code>capital AND of AND Hungary</code>
*/
public QueryStringQueryBuilder defaultOperator(Operator defaultOperator) {
Expand Down Expand Up @@ -342,6 +343,14 @@ public QueryStringQueryBuilder timeZone(String timeZone) {
return this;
}

/**
* Set to <tt>true</tt> to enable escaping of the query string
*/
public QueryStringQueryBuilder escape(boolean escape) {
this.escape = escape;
return this;
}

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(QueryStringQueryParser.NAME);
Expand Down Expand Up @@ -431,6 +440,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (timeZone != null) {
builder.field("time_zone", timeZone);
}
if (escape != null) {
builder.field("escape", escape);
}
builder.endObject();
}
}

0 comments on commit bce15d1

Please sign in to comment.