Skip to content

Commit

Permalink
Fixed quote_field_suffix in query_string (#29332)
Browse files Browse the repository at this point in the history
This change fixes the handling of the `quote_field_suffix` option on `query_string`
 query. The expansion was not applied to default fields query.

Closes #29324
  • Loading branch information
jimczi committed Apr 4, 2018
1 parent cdcd0d9 commit fff4e10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static org.elasticsearch.common.lucene.search.Queries.newLenientFieldQuery;
import static org.elasticsearch.common.lucene.search.Queries.newUnmappedFieldQuery;
import static org.elasticsearch.index.search.QueryParserHelper.resolveMappingField;
import static org.elasticsearch.index.search.QueryParserHelper.resolveMappingFields;

/**
* A {@link XQueryParser} that uses the {@link MapperService} in order to build smarter
Expand Down Expand Up @@ -265,6 +266,8 @@ private Map<String, Float> extractMultiFields(String field, boolean quoted) {
// Filters unsupported fields if a pattern is requested
// Filters metadata fields if all fields are requested
return resolveMappingField(context, field, 1.0f, !allFields, !multiFields, quoted ? quoteFieldSuffix : null);
} else if (quoted && quoteFieldSuffix != null) {
return resolveMappingFields(context, fieldsAndWeights, quoteFieldSuffix);
} else {
return fieldsAndWeights;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,37 @@ public void testQuoteAnalyzer() throws Exception {
assertEquals(expectedQuery, query);
}

public void testQuoteFieldSuffix() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
QueryShardContext context = createShardContext();
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("bar")
.quoteFieldSuffix("_2")
.field(STRING_FIELD_NAME)
.doToQuery(context)
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME_2, "bar")),
new QueryStringQueryBuilder("\"bar\"")
.quoteFieldSuffix("_2")
.field(STRING_FIELD_NAME)
.doToQuery(context)
);

// Now check what happens if the quote field does not exist
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("bar")
.quoteFieldSuffix(".quote")
.field(STRING_FIELD_NAME)
.doToQuery(context)
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("\"bar\"")
.quoteFieldSuffix(".quote")
.field(STRING_FIELD_NAME)
.doToQuery(context)
);
}

public void testToFuzzyQuery() throws Exception {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);

Expand Down

0 comments on commit fff4e10

Please sign in to comment.