diff --git a/docs/changelog/94369.yaml b/docs/changelog/94369.yaml new file mode 100644 index 0000000000000..6666e6810950c --- /dev/null +++ b/docs/changelog/94369.yaml @@ -0,0 +1,5 @@ +pr: 94369 +summary: Fix NPE thrown by prefix query in strange scenarios +area: Search +type: bug +issues: [] diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java index 922fff063f052..b04d8321b9b11 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java @@ -252,10 +252,13 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + MultiTermQuery.RewriteMethod rewriteMethod ) { // Disable scoring - return new ConstantScoreQuery(super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context)); + return new ConstantScoreQuery( + super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context, rewriteMethod) + ); } @Override @@ -276,8 +279,14 @@ public IntervalsSource fuzzyIntervals( boolean transpositions, SearchExecutionContext context ) { - FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term(name(), term), maxDistance, prefixLength, 128, transpositions); - fuzzyQuery.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); + FuzzyQuery fuzzyQuery = new FuzzyQuery( + new Term(name(), term), + maxDistance, + prefixLength, + 128, + transpositions, + MultiTermQuery.CONSTANT_SCORE_REWRITE + ); IntervalsSource fuzzyIntervals = Intervals.multiterm(fuzzyQuery.getAutomata(), term); return toIntervalsSource(fuzzyIntervals, fuzzyQuery, context); } diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldMapper.java index 8ab0968384467..48daad7269319 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldMapper.java @@ -413,7 +413,9 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew SpanMultiTermQueryWrapper spanMulti = new SpanMultiTermQueryWrapper<>( new PrefixQuery(new Term(name(), indexedValueForSearch(value))) ); - spanMulti.setRewriteMethod(method); + if (method != null) { + spanMulti.setRewriteMethod(method); + } return spanMulti; } } @@ -464,8 +466,9 @@ public Query prefixQuery( automata.add(Automata.makeAnyChar()); } Automaton automaton = Operations.concatenate(automata); - AutomatonQuery query = new AutomatonQuery(new Term(name(), value + "*"), automaton); - query.setRewriteMethod(method); + AutomatonQuery query = method == null + ? new AutomatonQuery(new Term(name(), value + "*"), automaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, false) + : new AutomatonQuery(new Term(name(), value + "*"), automaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, false, method); return new BooleanQuery.Builder().add(query, BooleanClause.Occur.SHOULD) .add(new TermQuery(new Term(parentField, value)), BooleanClause.Occur.SHOULD) .build(); @@ -649,7 +652,9 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew SpanMultiTermQueryWrapper spanMulti = new SpanMultiTermQueryWrapper<>( new PrefixQuery(new Term(name(), indexedValueForSearch(value))) ); - spanMulti.setRewriteMethod(method); + if (method != null) { + spanMulti.setRewriteMethod(method); + } return spanMulti; } } diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldTypeTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldTypeTests.java index 5ad01f1922e34..46bd5f169c172 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldTypeTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SearchAsYouTypeFieldTypeTests.java @@ -109,7 +109,7 @@ public void testPrefixQuery() { // this term should be a length that can be rewriteable to a term query on the prefix field final String withinBoundsTerm = "foo"; assertThat( - fieldType.prefixQuery(withinBoundsTerm, CONSTANT_SCORE_REWRITE, randomMockContext()), + fieldType.prefixQuery(withinBoundsTerm, randomBoolean() ? CONSTANT_SCORE_REWRITE : null, randomMockContext()), equalTo(new ConstantScoreQuery(new TermQuery(new Term(NAME + "._index_prefix", withinBoundsTerm)))) ); @@ -118,13 +118,13 @@ public void testPrefixQuery() { // this term should be too long to be rewriteable to a term query on the prefix field final String longTerm = "toolongforourprefixfieldthistermis"; assertThat( - fieldType.prefixQuery(longTerm, CONSTANT_SCORE_REWRITE, MOCK_CONTEXT), + fieldType.prefixQuery(longTerm, randomBoolean() ? null : CONSTANT_SCORE_REWRITE, MOCK_CONTEXT), equalTo(new PrefixQuery(new Term(NAME, longTerm))) ); ElasticsearchException ee = expectThrows( ElasticsearchException.class, - () -> fieldType.prefixQuery(longTerm, CONSTANT_SCORE_REWRITE, MOCK_CONTEXT_DISALLOW_EXPENSIVE) + () -> fieldType.prefixQuery(longTerm, randomBoolean() ? null : CONSTANT_SCORE_REWRITE, MOCK_CONTEXT_DISALLOW_EXPENSIVE) ); assertEquals( "[prefix] queries cannot be executed when 'search.allow_expensive_queries' is set to false. " diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/ICUCollationKeywordFieldMapper.java index 8148d0bd3df2d..9d58549763b62 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/plugin/analysis/icu/ICUCollationKeywordFieldMapper.java @@ -143,7 +143,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { throw new UnsupportedOperationException("[fuzzy] queries are not supported on [" + CONTENT_TYPE + "] fields."); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractScriptFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractScriptFieldType.java index b84294168397c..ca3f5c0e1be5f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractScriptFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractScriptFieldType.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.CompositeFieldScript; import org.elasticsearch.script.Script; @@ -103,7 +104,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { throw new IllegalArgumentException(unsupported("fuzzy", "keyword and text")); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java index 04ab0af646af3..a552f72a012bf 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java @@ -468,11 +468,12 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { failIfNotIndexedNorDocValuesFallback(context); if (isIndexed()) { - return super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context); + return super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context, rewriteMethod); } else { return StringScriptFieldFuzzyQuery.build( new Script(""), diff --git a/server/src/main/java/org/elasticsearch/index/mapper/KeywordScriptFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/KeywordScriptFieldType.java index 8239ed3347c6e..b09076083f872 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/KeywordScriptFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/KeywordScriptFieldType.java @@ -8,12 +8,14 @@ package org.elasticsearch.index.mapper; +import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.MultiTermQuery.RewriteMethod; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.StringScriptFieldData; import org.elasticsearch.index.query.SearchExecutionContext; @@ -124,7 +126,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { applyScriptContext(context); return StringScriptFieldFuzzyQuery.build( diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index cb88018a0e5e3..5a3cd7aff78da 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -248,13 +248,25 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { throw new IllegalArgumentException( "Can only use fuzzy queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } + public Query fuzzyQuery( + Object value, + Fuzziness fuzziness, + int prefixLength, + int maxExpansions, + boolean transpositions, + SearchExecutionContext context + ) { + return fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context, null); + } + // Case sensitive form of prefix query public final Query prefixQuery(String value, @Nullable MultiTermQuery.RewriteMethod method, SearchExecutionContext context) { return prefixQuery(value, method, false, context); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java index dccd4e1041e55..a7de1194ddceb 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java @@ -159,7 +159,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { throw new QueryShardException(context, fail("fuzzy query")); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java index 2842e9476bb5a..f785cc38c5c2a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java @@ -20,17 +20,19 @@ import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; +import org.apache.lucene.util.automaton.Operations; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.lucene.BytesRefs; -import org.elasticsearch.common.lucene.search.AutomatonQueries; import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.query.SearchExecutionContext; -import org.elasticsearch.index.query.support.QueryParsers; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.elasticsearch.common.lucene.search.AutomatonQueries.caseInsensitivePrefix; +import static org.elasticsearch.common.lucene.search.AutomatonQueries.toCaseInsensitiveWildcardAutomaton; import static org.elasticsearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES; /** Base class for {@link MappedFieldType} implementations that use the same @@ -59,7 +61,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { if (context.allowExpensiveQueries() == false) { throw new ElasticsearchException( @@ -87,19 +90,19 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool ); } failIfNotIndexed(); + Term prefix = new Term(name(), indexedValueForSearch(value)); if (caseInsensitive) { - AutomatonQuery query = AutomatonQueries.caseInsensitivePrefixQuery((new Term(name(), indexedValueForSearch(value)))); - if (method != null) { - query.setRewriteMethod(method); - } - return query; - + return method == null + ? new AutomatonQuery(prefix, caseInsensitivePrefix(prefix.text()), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, false) + : new AutomatonQuery( + prefix, + caseInsensitivePrefix(prefix.text()), + Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, + false, + method + ); } - PrefixQuery query = new PrefixQuery(new Term(name(), indexedValueForSearch(value))); - if (method != null) { - query.setRewriteMethod(method); - } - return query; + return method == null ? new PrefixQuery(prefix) : new PrefixQuery(prefix, method); } public static final String normalizeWildcardPattern(String fieldname, String value, Analyzer normalizer) { @@ -164,13 +167,17 @@ protected Query wildcardQuery( term = new Term(name(), indexedValueForSearch(value)); } if (caseInsensitive) { - AutomatonQuery query = AutomatonQueries.caseInsensitiveWildcardQuery(term); - QueryParsers.setRewriteMethod(query, method); - return query; + return method == null + ? new AutomatonQuery(term, toCaseInsensitiveWildcardAutomaton(term, Integer.MAX_VALUE)) + : new AutomatonQuery( + term, + toCaseInsensitiveWildcardAutomaton(term, Integer.MAX_VALUE), + Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, + false, + method + ); } - WildcardQuery query = new WildcardQuery(term); - QueryParsers.setRewriteMethod(query, method); - return query; + return method == null ? new WildcardQuery(term) : new WildcardQuery(term, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, method); } @Override @@ -188,11 +195,16 @@ public Query regexpQuery( ); } failIfNotIndexed(); - RegexpQuery query = new RegexpQuery(new Term(name(), indexedValueForSearch(value)), syntaxFlags, matchFlags, maxDeterminizedStates); - if (method != null) { - query.setRewriteMethod(method); - } - return query; + return method == null + ? new RegexpQuery(new Term(name(), indexedValueForSearch(value)), syntaxFlags, matchFlags, maxDeterminizedStates) + : new RegexpQuery( + new Term(name(), indexedValueForSearch(value)), + syntaxFlags, + matchFlags, + RegexpQuery.DEFAULT_PROVIDER, + maxDeterminizedStates, + method + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index 51cf935654e84..a8438407a68f9 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -53,6 +53,7 @@ import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.xcontent.support.XContentMapValues; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.IndexAnalyzers; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -618,8 +619,9 @@ public Query prefixQuery( automata.add(Automata.makeAnyChar()); } Automaton automaton = Operations.concatenate(automata); - AutomatonQuery query = new AutomatonQuery(new Term(name(), value + "*"), automaton); - query.setRewriteMethod(method); + AutomatonQuery query = method == null + ? new AutomatonQuery(new Term(name(), value + "*"), automaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, false) + : new AutomatonQuery(new Term(name(), value + "*"), automaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, false, method); return new BooleanQuery.Builder().add(query, BooleanClause.Occur.SHOULD) .add(new TermQuery(new Term(parentField.name(), value)), BooleanClause.Occur.SHOULD) .build(); @@ -809,7 +811,9 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew SpanMultiTermQueryWrapper spanMulti = new SpanMultiTermQueryWrapper<>( new PrefixQuery(new Term(name(), indexedValueForSearch(value))) ); - spanMulti.setRewriteMethod(method); + if (method != null) { + spanMulti.setRewriteMethod(method); + } return spanMulti; } } @@ -1064,10 +1068,13 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { // Disable scoring - return new ConstantScoreQuery(super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context)); + return new ConstantScoreQuery( + super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context, rewriteMethod) + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java index f60611b08f1f9..52a171d4707e9 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.lucene.search.AutomatonQueries; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FieldDataContext; @@ -272,7 +273,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { throw new UnsupportedOperationException( "[fuzzy] queries are not currently supported on keyed " + "[" + CONTENT_TYPE + "] fields." diff --git a/server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java index 3d28b89d45f76..34f17a2ebca7f 100644 --- a/server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.search.FuzzyQuery; -import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; @@ -332,12 +331,15 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { throw new IllegalStateException("Rewrite first"); } String rewrite = this.rewrite; - Query query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context); - if (query instanceof MultiTermQuery) { - MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE); - QueryParsers.setRewriteMethod((MultiTermQuery) query, rewriteMethod); - } - return query; + return fieldType.fuzzyQuery( + value, + fuzziness, + prefixLength, + maxExpansions, + transpositions, + context, + QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE) + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index c802209ddbb7b..ad9afc79faf67 100644 --- a/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -285,16 +285,21 @@ protected Query doToQuery(SearchExecutionContext context) throws QueryShardExcep query = fieldType.regexpQuery(value, sanitisedSyntaxFlag, matchFlagsValue, maxDeterminizedStates, method, context); } if (query == null) { - RegexpQuery regexpQuery = new RegexpQuery( - new Term(fieldName, BytesRefs.toBytesRef(value)), - sanitisedSyntaxFlag, - matchFlagsValue, - maxDeterminizedStates - ); - if (method != null) { - regexpQuery.setRewriteMethod(method); - } - query = regexpQuery; + return method == null + ? new RegexpQuery( + new Term(fieldName, BytesRefs.toBytesRef(value)), + sanitisedSyntaxFlag, + matchFlagsValue, + maxDeterminizedStates + ) + : new RegexpQuery( + new Term(fieldName, BytesRefs.toBytesRef(value)), + sanitisedSyntaxFlag, + matchFlagsValue, + RegexpQuery.DEFAULT_PROVIDER, + maxDeterminizedStates, + method + ); } return query; } diff --git a/server/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java b/server/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java index 60e18634e7999..1fb80cd819bed 100644 --- a/server/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java +++ b/server/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java @@ -26,13 +26,6 @@ private QueryParsers() { } - public static void setRewriteMethod(MultiTermQuery query, @Nullable MultiTermQuery.RewriteMethod rewriteMethod) { - if (rewriteMethod == null) { - return; - } - query.setRewriteMethod(rewriteMethod); - } - public static MultiTermQuery.RewriteMethod parseRewriteMethod(@Nullable String rewriteMethod, DeprecationHandler deprecationHandler) { return parseRewriteMethod(rewriteMethod, MultiTermQuery.CONSTANT_SCORE_REWRITE, deprecationHandler); } diff --git a/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java b/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java index 524fe4a1a1be9..dd08eb7cc31b2 100644 --- a/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java +++ b/server/src/main/java/org/elasticsearch/index/search/MatchQueryParser.java @@ -43,7 +43,6 @@ import org.elasticsearch.index.mapper.TextSearchInfo; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.index.query.ZeroTermsQueryOption; -import org.elasticsearch.index.query.support.QueryParsers; import org.elasticsearch.lucene.analysis.miscellaneous.DisableGraphAttribute; import java.io.IOException; @@ -471,21 +470,22 @@ private SpanQuery createSpanQuery(TokenStream in, String field, boolean isPrefix @Override protected Query newTermQuery(Term term, float boost) { - Supplier querySupplier; + final Supplier querySupplier; if (fuzziness != null) { - querySupplier = () -> { - Query query = fieldType.fuzzyQuery(term.text(), fuzziness, fuzzyPrefixLength, maxExpansions, transpositions, context); - if (query instanceof FuzzyQuery) { - QueryParsers.setRewriteMethod((FuzzyQuery) query, fuzzyRewriteMethod); - } - return query; - }; + querySupplier = () -> fieldType.fuzzyQuery( + term.text(), + fuzziness, + fuzzyPrefixLength, + maxExpansions, + transpositions, + context, + fuzzyRewriteMethod + ); } else { querySupplier = () -> fieldType.termQuery(term.bytes(), context); } try { - Query query = querySupplier.get(); - return query; + return querySupplier.get(); } catch (RuntimeException e) { if (lenient) { return newLenientFieldQuery(fieldType.name(), e); diff --git a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java index ee08242557a87..89fc7be8d0fd2 100644 --- a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java +++ b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java @@ -47,7 +47,6 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.index.query.ZeroTermsQueryOption; -import org.elasticsearch.index.query.support.QueryParsers; import java.io.IOException; import java.time.ZoneId; @@ -490,7 +489,8 @@ private Query getFuzzyQuerySingle(String field, String termStr, int minSimilarit getFuzzyPrefixLength(), fuzzyMaxExpansions, fuzzyTranspositions, - context + context, + null ); } catch (RuntimeException e) { if (lenient) { @@ -503,9 +503,9 @@ private Query getFuzzyQuerySingle(String field, String termStr, int minSimilarit @Override protected Query newFuzzyQuery(Term term, float minimumSimilarity, int prefixLength) { int numEdits = Fuzziness.fromEdits((int) minimumSimilarity).asDistance(term.text()); - FuzzyQuery query = new FuzzyQuery(term, numEdits, prefixLength, fuzzyMaxExpansions, fuzzyTranspositions); - QueryParsers.setRewriteMethod(query, fuzzyRewriteMethod); - return query; + return fuzzyRewriteMethod == null + ? new FuzzyQuery(term, numEdits, prefixLength, fuzzyMaxExpansions, fuzzyTranspositions) + : new FuzzyQuery(term, numEdits, prefixLength, fuzzyMaxExpansions, fuzzyTranspositions, fuzzyRewriteMethod); } @Override diff --git a/server/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java b/server/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java index 4992b2e87e0d1..694caa9d475e9 100644 --- a/server/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java +++ b/server/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java @@ -96,8 +96,7 @@ public void testVectorHighlighterPrefixQuery() throws Exception { 30 ); assertThat(fragment, nullValue()); - - prefixQuery.setRewriteMethod(PrefixQuery.SCORING_BOOLEAN_REWRITE); + prefixQuery = new PrefixQuery(new Term("content", "ba"), PrefixQuery.SCORING_BOOLEAN_REWRITE); Query rewriteQuery = prefixQuery.rewrite(reader); fragment = highlighter.getBestFragment(highlighter.getFieldQuery(rewriteQuery), reader, topDocs.scoreDocs[0].doc, "content", 30); assertThat(fragment, notNullValue()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java index e63e5e816483f..819146767c0b6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java @@ -140,13 +140,13 @@ public void testIndexPrefixes() { ConstantScoreTextFieldType ft = createFieldType(); ft.setIndexPrefixes(2, 10); - Query q = ft.prefixQuery("goin", CONSTANT_SCORE_REWRITE, false, randomMockContext()); + Query q = ft.prefixQuery("goin", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, randomMockContext()); assertEquals(new ConstantScoreQuery(new TermQuery(new Term("field._index_prefix", "goin"))), q); - q = ft.prefixQuery("internationalisatio", CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT); + q = ft.prefixQuery("internationalisatio", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT); assertEquals(new PrefixQuery(new Term("field", "internationalisatio")), q); - q = ft.prefixQuery("Internationalisatio", CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT); + q = ft.prefixQuery("Internationalisatio", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT); assertEquals(AutomatonQueries.caseInsensitivePrefixQuery(new Term("field", "Internationalisatio")), q); ElasticsearchException ee = expectThrows( @@ -159,7 +159,7 @@ public void testIndexPrefixes() { ee.getMessage() ); - q = ft.prefixQuery("g", CONSTANT_SCORE_REWRITE, false, randomMockContext()); + q = ft.prefixQuery("g", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, randomMockContext()); Automaton automaton = Operations.concatenate(Arrays.asList(Automata.makeChar('g'), Automata.makeAnyChar())); Query expected = new ConstantScoreQuery( diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java index 0c54a1be33384..46dc5725b52ff 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java @@ -147,13 +147,13 @@ public void testIndexPrefixes() { TextFieldType ft = createFieldType(); ft.setIndexPrefixes(2, 10); - Query q = ft.prefixQuery("goin", CONSTANT_SCORE_REWRITE, false, randomMockContext()); + Query q = ft.prefixQuery("goin", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, randomMockContext()); assertEquals(new ConstantScoreQuery(new TermQuery(new Term("field._index_prefix", "goin"))), q); - q = ft.prefixQuery("internationalisatio", CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT); + q = ft.prefixQuery("internationalisatio", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT); assertEquals(new PrefixQuery(new Term("field", "internationalisatio")), q); - q = ft.prefixQuery("Internationalisatio", CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT); + q = ft.prefixQuery("Internationalisatio", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT); assertEquals(AutomatonQueries.caseInsensitivePrefixQuery(new Term("field", "Internationalisatio")), q); ElasticsearchException ee = expectThrows( @@ -166,15 +166,13 @@ public void testIndexPrefixes() { ee.getMessage() ); - q = ft.prefixQuery("g", CONSTANT_SCORE_REWRITE, false, randomMockContext()); + q = ft.prefixQuery("g", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, randomMockContext()); Automaton automaton = Operations.concatenate(Arrays.asList(Automata.makeChar('g'), Automata.makeAnyChar())); - Query expected = new ConstantScoreQuery( new BooleanQuery.Builder().add(new AutomatonQuery(new Term("field._index_prefix", "g*"), automaton), BooleanClause.Occur.SHOULD) .add(new TermQuery(new Term("field", "g")), BooleanClause.Occur.SHOULD) .build() ); - assertThat(q, equalTo(expected)); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/flattened/KeyedFlattenedFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/flattened/KeyedFlattenedFieldTypeTests.java index 8716b38b4b94d..74f63e2fb3830 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/flattened/KeyedFlattenedFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/flattened/KeyedFlattenedFieldTypeTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.mapper.flattened; import org.apache.lucene.index.Term; -import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermInSetQuery; @@ -33,6 +32,7 @@ import java.util.Map; import java.util.Set; +import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -93,14 +93,14 @@ public void testPrefixQuery() { KeyedFlattenedFieldType ft = createFieldType(); Query expected = new PrefixQuery(new Term(ft.name(), "key\0val")); - assertEquals(expected, ft.prefixQuery("val", MultiTermQuery.CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT)); + assertEquals(expected, ft.prefixQuery("val", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT)); expected = AutomatonQueries.caseInsensitivePrefixQuery(new Term(ft.name(), "key\0vAl")); - assertEquals(expected, ft.prefixQuery("vAl", MultiTermQuery.CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT)); + assertEquals(expected, ft.prefixQuery("vAl", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, true, MOCK_CONTEXT)); ElasticsearchException ee = expectThrows( ElasticsearchException.class, - () -> ft.prefixQuery("val", MultiTermQuery.CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT_DISALLOW_EXPENSIVE) + () -> ft.prefixQuery("val", randomBoolean() ? null : CONSTANT_SCORE_REWRITE, false, MOCK_CONTEXT_DISALLOW_EXPENSIVE) ); assertEquals( "[prefix] queries cannot be executed when 'search.allow_expensive_queries' is set to false. " diff --git a/server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java b/server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java index 8c2ba79a81812..b71f53b0da55a 100644 --- a/server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java +++ b/server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java @@ -925,14 +925,13 @@ public void testCancellationDuringRewrite() throws IOException { try (IndexReader reader = DirectoryReader.open(dir)) { TestSearchContext context = new TestSearchContext(null, indexShard, newContextSearcher(reader)); - PrefixQuery prefixQuery = new PrefixQuery(new Term("foo", "a")); - prefixQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE); + PrefixQuery prefixQuery = new PrefixQuery(new Term("foo", "a"), MultiTermQuery.SCORING_BOOLEAN_REWRITE); context.parsedQuery(new ParsedQuery(prefixQuery)); SearchShardTask task = new SearchShardTask(randomLong(), "transport", "", "", TaskId.EMPTY_TASK_ID, Collections.emptyMap()); TaskCancelHelper.cancel(task, "simulated"); context.setTask(task); context.searcher().addQueryCancellation(task::ensureNotCancelled); - expectThrows(TaskCancelledException.class, () -> context.rewrittenQuery()); + expectThrows(TaskCancelledException.class, context::rewrittenQuery); } } } diff --git a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java index ac3bbddfcd151..5dd04a9e79645 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java +++ b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.IndexFieldData; @@ -226,7 +227,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { if (this.value == null) { return new MatchNoDocsQuery(); diff --git a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionFieldWildcardQuery.java b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionFieldWildcardQuery.java index 7bdc2e27c58d9..3b0686870f7e5 100644 --- a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionFieldWildcardQuery.java +++ b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionFieldWildcardQuery.java @@ -43,6 +43,10 @@ class VersionFieldWildcardQuery extends AutomatonQuery { super(term, toAutomaton(term, caseInsensitive), Integer.MAX_VALUE, true); } + VersionFieldWildcardQuery(Term term, boolean caseInsensitive, RewriteMethod rewriteMethod) { + super(term, toAutomaton(term, caseInsensitive), Integer.MAX_VALUE, true, rewriteMethod); + } + private static Automaton toAutomaton(Term wildcardquery, boolean caseInsensitive) { List automata = new ArrayList<>(); diff --git a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java index cc1d20256b484..f0d86da6efe8d 100644 --- a/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java +++ b/x-pack/plugin/mapper-version/src/main/java/org/elasticsearch/xpack/versionfield/VersionStringFieldMapper.java @@ -52,7 +52,6 @@ import org.elasticsearch.index.mapper.TextSearchInfo; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.index.query.SearchExecutionContext; -import org.elasticsearch.index.query.support.QueryParsers; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.xcontent.XContentParser; @@ -66,6 +65,9 @@ import java.util.List; import java.util.Map; +import static org.apache.lucene.search.FuzzyQuery.defaultRewriteMethod; +import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE; +import static org.apache.lucene.search.RegexpQuery.DEFAULT_PROVIDER; import static org.elasticsearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES; import static org.elasticsearch.xpack.versionfield.VersionEncoder.encodeVersion; @@ -178,7 +180,14 @@ public Query regexpQuery( "[regexp] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false." ); } - RegexpQuery query = new RegexpQuery(new Term(name(), new BytesRef(value)), syntaxFlags, matchFlags, maxDeterminizedStates) { + return new RegexpQuery( + new Term(name(), new BytesRef(value)), + syntaxFlags, + matchFlags, + DEFAULT_PROVIDER, + maxDeterminizedStates, + method == null ? CONSTANT_SCORE_REWRITE : method + ) { @Override protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException { @@ -196,11 +205,6 @@ protected AcceptStatus accept(BytesRef term) throws IOException { }; } }; - - if (method != null) { - query.setRewriteMethod(method); - } - return query; } /** @@ -217,7 +221,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { if (context.allowExpensiveQueries() == false) { throw new ElasticsearchException( @@ -229,7 +234,8 @@ public Query fuzzyQuery( fuzziness.asDistance(BytesRefs.toString(value)), prefixLength, maxExpansions, - transpositions + transpositions, + rewriteMethod == null ? defaultRewriteMethod(maxExpansions) : rewriteMethod ) { @Override protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException { @@ -264,9 +270,9 @@ public Query wildcardQuery( ); } - VersionFieldWildcardQuery query = new VersionFieldWildcardQuery(new Term(name(), value), caseInsensitive); - QueryParsers.setRewriteMethod(query, method); - return query; + return method == null + ? new VersionFieldWildcardQuery(new Term(name(), value), caseInsensitive) + : new VersionFieldWildcardQuery(new Term(name(), value), caseInsensitive, method); } @Override diff --git a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java index 6ec41d3d1afb4..40fc19f2f960d 100644 --- a/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java +++ b/x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java @@ -51,6 +51,7 @@ import org.elasticsearch.common.lucene.search.AutomatonQueries; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.unit.Fuzziness; +import org.elasticsearch.core.Nullable; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.LowercaseNormalizer; import org.elasticsearch.index.analysis.NamedAnalyzer; @@ -628,8 +629,7 @@ private void addClause(String token, BooleanQuery.Builder bqBuilder, Occur occur TermQuery tq = new TermQuery(new Term(name(), token)); bqBuilder.add(new BooleanClause(tq, occur)); } else { - PrefixQuery wq = new PrefixQuery(new Term(name(), token)); - wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); + PrefixQuery wq = new PrefixQuery(new Term(name(), token), MultiTermQuery.CONSTANT_SCORE_REWRITE); bqBuilder.add(new BooleanClause(wq, occur)); } } @@ -680,8 +680,7 @@ public Query rangeQuery( TermQuery tq = new TermQuery(new Term(name(), token)); bqBuilder.add(new BooleanClause(tq, Occur.FILTER)); } else { - PrefixQuery wq = new PrefixQuery(new Term(name(), token)); - wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); + PrefixQuery wq = new PrefixQuery(new Term(name(), token), MultiTermQuery.CONSTANT_SCORE_REWRITE); bqBuilder.add(new BooleanClause(wq, Occur.FILTER)); } } @@ -706,7 +705,8 @@ public Query fuzzyQuery( int prefixLength, int maxExpansions, boolean transpositions, - SearchExecutionContext context + SearchExecutionContext context, + @Nullable MultiTermQuery.RewriteMethod rewriteMethod ) { String searchTerm = BytesRefs.toString(value); try { @@ -767,13 +767,22 @@ public Query fuzzyQuery( BooleanQuery ngramQ = approxBuilder.build(); // Verification query - FuzzyQuery fq = new FuzzyQuery( - new Term(name(), searchTerm), - fuzziness.asDistance(searchTerm), - prefixLength, - maxExpansions, - transpositions - ); + FuzzyQuery fq = rewriteMethod == null + ? new FuzzyQuery( + new Term(name(), searchTerm), + fuzziness.asDistance(searchTerm), + prefixLength, + maxExpansions, + transpositions + ) + : new FuzzyQuery( + new Term(name(), searchTerm), + fuzziness.asDistance(searchTerm), + prefixLength, + maxExpansions, + transpositions, + rewriteMethod + ); if (ngramQ.clauses().size() == 0) { return new BinaryDvConfirmedAutomatonQuery(new MatchAllDocsQuery(), name(), searchTerm, fq.getAutomata().automaton); }