In MatchQuery, remove a check for fragile search analyzers. (#33927)
As far as I can tell this guard against fragile analyzers is no longer relevant, since we stopped setting special analyzers on numeric fields (3bf6f4). Instead of removing the guard completely, I opted to keep a check for untokenized + unnormalized fields to avoid going through the analysis process unnecessarily. My motivation for simplifying this check is that I'd like to add support for `split_queries_on_whitespace` to the new 'queryable object' fields. As it stands, I would have to add a dedicated instanceof check for the new mapper, which is not optimal.
This commit is contained in:
parent
78e483e8d8
commit
8e8bd56cc7
|
@ -48,10 +48,10 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
|
||||
import org.elasticsearch.common.lucene.search.Queries;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.index.mapper.KeywordFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.index.query.support.QueryParsers;
|
||||
|
@ -253,22 +253,17 @@ public class MatchQuery {
|
|||
}
|
||||
final String field = fieldType.name();
|
||||
|
||||
Analyzer analyzer = getAnalyzer(fieldType, type == Type.PHRASE);
|
||||
assert analyzer != null;
|
||||
|
||||
/*
|
||||
* If the user forced an analyzer we really don't care if they are
|
||||
* searching a type that wants term queries to be used with query string
|
||||
* because the QueryBuilder will take care of it. If they haven't forced
|
||||
* an analyzer then types like NumberFieldType that want terms with
|
||||
* query string will blow up because their analyzer isn't capable of
|
||||
* passing through QueryBuilder.
|
||||
* If a keyword analyzer is used, we know that further analysis isn't
|
||||
* needed and can immediately return a term query.
|
||||
*/
|
||||
boolean noForcedAnalyzer = this.analyzer == null;
|
||||
if (fieldType.tokenized() == false && noForcedAnalyzer &&
|
||||
fieldType instanceof KeywordFieldMapper.KeywordFieldType == false) {
|
||||
if (analyzer == Lucene.KEYWORD_ANALYZER) {
|
||||
return blendTermQuery(new Term(fieldName, value.toString()), fieldType);
|
||||
}
|
||||
|
||||
Analyzer analyzer = getAnalyzer(fieldType, type == Type.PHRASE);
|
||||
assert analyzer != null;
|
||||
MatchQueryBuilder builder = new MatchQueryBuilder(analyzer, fieldType);
|
||||
builder.setEnablePositionIncrements(this.enablePositionIncrements);
|
||||
if (hasPositions(fieldType)) {
|
||||
|
|
Loading…
Reference in New Issue