From f8fc0f3ebeaa80cec8e0fce99ae8128bf4e27716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Sat, 2 Sep 2017 11:53:02 +0200 Subject: [PATCH] [Tests] Check that quoteAnalyzer overrides analyzer in `query_string` query (#26473) Adding a check to QueryStringQueryBuilderTests that checks the override behaviour of `quote_analyzer`, also adding documentation explaining the use of this parameter in `query_string` query. Closes #25417 --- .../query/QueryStringQueryBuilderTests.java | 24 +++++++++++++++++-- .../query-dsl/query-string-query.asciidoc | 7 +++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index d2183dfcc20..9609c8415a7 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -45,10 +45,8 @@ import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.automaton.TooComplexToDeterminizeException; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.settings.Settings; @@ -1009,6 +1007,28 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase 0); + // Prefix + Query query = new QueryStringQueryBuilder("ONE \"TWO THREE\"") + .field(STRING_FIELD_NAME) + .analyzer("whitespace") + .quoteAnalyzer("simple") + .toQuery(createShardContext()); + Query expectedQuery = + new BooleanQuery.Builder() + .add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "ONE")), Occur.SHOULD)) + .add(new BooleanClause(new PhraseQuery.Builder() + .add(new Term(STRING_FIELD_NAME, "two"), 0) + .add(new Term(STRING_FIELD_NAME, "three"), 1) + .build(), Occur.SHOULD)) + .build(); + assertEquals(expectedQuery, query); + } + private static IndexMetaData newIndexMeta(String name, Settings oldIndexSettings, Settings indexSettings) { Settings build = Settings.builder().put(oldIndexSettings) .put(indexSettings) diff --git a/docs/reference/query-dsl/query-string-query.asciidoc b/docs/reference/query-dsl/query-string-query.asciidoc index a20ac345c20..2b91c9cd6e1 100644 --- a/docs/reference/query-dsl/query-string-query.asciidoc +++ b/docs/reference/query-dsl/query-string-query.asciidoc @@ -63,6 +63,11 @@ with default operator of `AND`, the same query is translated to |`analyzer` |The analyzer name used to analyze the query string. +|`quote_analyzer` |The name of the analyzer that is used to analyze +quoted phrases in the query string. For those parts, it overrides other +analyzers that are set using the `analyzer` parameter or the +<> setting. + |`allow_leading_wildcard` |When set, `*` or `?` are allowed as the first character. Defaults to `true`. @@ -73,7 +78,7 @@ increments in result queries. Defaults to `true`. expand to. Defaults to `50` |`fuzziness` |Set the fuzziness for fuzzy queries. Defaults -to `AUTO`. See <> for allowed settings. +to `AUTO`. See <> for allowed settings. |`fuzzy_prefix_length` |Set the prefix length for fuzzy queries. Default is `0`.