[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
This commit is contained in:
parent
1757bd8d92
commit
f8fc0f3ebe
|
@ -45,10 +45,8 @@ import org.apache.lucene.search.spans.SpanQuery;
|
||||||
import org.apache.lucene.search.spans.SpanTermQuery;
|
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
|
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.ParsingException;
|
|
||||||
import org.elasticsearch.common.compress.CompressedXContent;
|
import org.elasticsearch.common.compress.CompressedXContent;
|
||||||
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
|
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -1009,6 +1007,28 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the quote analyzer should overwrite any other forced analyzer in quoted parts of the query
|
||||||
|
*/
|
||||||
|
public void testQuoteAnalyzer() throws Exception {
|
||||||
|
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 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) {
|
private static IndexMetaData newIndexMeta(String name, Settings oldIndexSettings, Settings indexSettings) {
|
||||||
Settings build = Settings.builder().put(oldIndexSettings)
|
Settings build = Settings.builder().put(oldIndexSettings)
|
||||||
.put(indexSettings)
|
.put(indexSettings)
|
||||||
|
|
|
@ -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.
|
|`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
|
||||||
|
<<search-quote-analyzer,`search_quote_analyzer`>> setting.
|
||||||
|
|
||||||
|`allow_leading_wildcard` |When set, `*` or `?` are allowed as the first
|
|`allow_leading_wildcard` |When set, `*` or `?` are allowed as the first
|
||||||
character. Defaults to `true`.
|
character. Defaults to `true`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue