Skip to content

Commit 163e32b

Browse files
committed
Query DSL: query_string - Expose QueryParser#setAutoGeneratePhraseQueries, closes elastic#964.
1 parent ee54e75 commit 163e32b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public static enum Operator {
4545

4646
private String analyzer;
4747

48+
private Boolean autoGeneratePhraseQueries;
49+
4850
private Boolean allowLeadingWildcard;
4951

5052
private Boolean lowercaseExpandedTerms;
@@ -184,6 +186,19 @@ public FieldQueryBuilder analyzer(String analyzer) {
184186
return this;
185187
}
186188

189+
/**
190+
* Set to true if phrase queries will be automatically generated
191+
* when the analyzer returns more than one term from whitespace
192+
* delimited text.
193+
* NOTE: this behavior may not be suitable for all languages.
194+
* <p>
195+
* Set to false if phrase queries should only be generated when
196+
* surrounded by double quotes.
197+
*/
198+
public void autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) {
199+
this.autoGeneratePhraseQueries = autoGeneratePhraseQueries;
200+
}
201+
187202
/**
188203
* Should leading wildcards be allowed or not. Defaults to <tt>true</tt>.
189204
*/
@@ -266,6 +281,9 @@ public FieldQueryBuilder analyzeWildcard(boolean analyzeWildcard) {
266281
if (analyzer != null) {
267282
builder.field("analyzer", analyzer);
268283
}
284+
if (autoGeneratePhraseQueries != null) {
285+
builder.field("auto_generate_phrase_queries", autoGeneratePhraseQueries);
286+
}
269287
if (allowLeadingWildcard != null) {
270288
builder.field("allow_leading_wildcard", allowLeadingWildcard);
271289
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryStringQueryBuilder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static enum Operator {
5252

5353
private String analyzer;
5454

55+
private Boolean autoGeneratePhraseQueries;
56+
5557
private Boolean allowLeadingWildcard;
5658

5759
private Boolean lowercaseExpandedTerms;
@@ -157,6 +159,19 @@ public QueryStringQueryBuilder analyzer(String analyzer) {
157159
return this;
158160
}
159161

162+
/**
163+
* Set to true if phrase queries will be automatically generated
164+
* when the analyzer returns more than one term from whitespace
165+
* delimited text.
166+
* NOTE: this behavior may not be suitable for all languages.
167+
* <p>
168+
* Set to false if phrase queries should only be generated when
169+
* surrounded by double quotes.
170+
*/
171+
public void autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) {
172+
this.autoGeneratePhraseQueries = autoGeneratePhraseQueries;
173+
}
174+
160175
/**
161176
* Should leading wildcards be allowed or not. Defaults to <tt>true</tt>.
162177
*/
@@ -260,6 +275,9 @@ public QueryStringQueryBuilder boost(float boost) {
260275
if (analyzer != null) {
261276
builder.field("analyzer", analyzer);
262277
}
278+
if (autoGeneratePhraseQueries != null) {
279+
builder.field("auto_generate_phrase_queries", autoGeneratePhraseQueries);
280+
}
263281
if (allowLeadingWildcard != null) {
264282
builder.field("allow_leading_wildcard", allowLeadingWildcard);
265283
}

0 commit comments

Comments
 (0)