Skip to content

Commit b7b7ffd

Browse files
committed
Remove some usages of ParseFieldMatcher in favour of using ParseField directly
Relates to elastic#19552 Relates to elastic#22130
1 parent 74acffa commit b7b7ffd

File tree

14 files changed

+39
-42
lines changed

14 files changed

+39
-42
lines changed

core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public FieldParser(Parser parser, EnumSet<XContentParser.Token> supportedTokens,
417417
}
418418

419419
public void assertSupports(String parserName, XContentParser.Token token, String currentFieldName, ParseFieldMatcher matcher) {
420-
if (matcher.match(currentFieldName, parseField) == false) {
420+
if (parseField.match(currentFieldName) == false) {
421421
throw new IllegalStateException("[" + parserName + "] parsefield doesn't accept: " + currentFieldName);
422422
}
423423
if (supportedTokens.contains(token) == false) {

core/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.elasticsearch.index.mapper;
2020

2121
import org.apache.lucene.codecs.PostingsFormat;
22-
import org.apache.lucene.document.Field;
2322
import org.apache.lucene.index.IndexableField;
2423
import org.apache.lucene.index.Term;
2524
import org.apache.lucene.search.suggest.document.Completion50PostingsFormat;
@@ -125,22 +124,22 @@ public static class TypeParser implements Mapper.TypeParser {
125124
if (fieldName.equals("type")) {
126125
continue;
127126
}
128-
if (parserContext.parseFieldMatcher().match(fieldName, Fields.ANALYZER)) {
127+
if (Fields.ANALYZER.match(fieldName)) {
129128
indexAnalyzer = getNamedAnalyzer(parserContext, fieldNode.toString());
130129
iterator.remove();
131-
} else if (parserContext.parseFieldMatcher().match(fieldName, Fields.SEARCH_ANALYZER)) {
130+
} else if (Fields.SEARCH_ANALYZER.match(fieldName)) {
132131
searchAnalyzer = getNamedAnalyzer(parserContext, fieldNode.toString());
133132
iterator.remove();
134-
} else if (parserContext.parseFieldMatcher().match(fieldName, Fields.PRESERVE_SEPARATORS)) {
133+
} else if (Fields.PRESERVE_SEPARATORS.match(fieldName)) {
135134
builder.preserveSeparators(Boolean.parseBoolean(fieldNode.toString()));
136135
iterator.remove();
137-
} else if (parserContext.parseFieldMatcher().match(fieldName, Fields.PRESERVE_POSITION_INCREMENTS)) {
136+
} else if (Fields.PRESERVE_POSITION_INCREMENTS.match(fieldName)) {
138137
builder.preservePositionIncrements(Boolean.parseBoolean(fieldNode.toString()));
139138
iterator.remove();
140-
} else if (parserContext.parseFieldMatcher().match(fieldName, Fields.MAX_INPUT_LENGTH)) {
139+
} else if (Fields.MAX_INPUT_LENGTH.match(fieldName)) {
141140
builder.maxInputLength(Integer.parseInt(fieldNode.toString()));
142141
iterator.remove();
143-
} else if (parserContext.parseFieldMatcher().match(fieldName, Fields.CONTEXTS)) {
142+
} else if (Fields.CONTEXTS.match(fieldName)) {
144143
builder.contextMappings(ContextMappings.load(fieldNode, parserContext.indexVersionCreated()));
145144
iterator.remove();
146145
} else if (parseMultiField(builder, name, parserContext, fieldName, fieldNode)) {

core/src/main/java/org/elasticsearch/index/mapper/ParentFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node,
114114
if (fieldName.equals("type")) {
115115
builder.type(fieldNode.toString());
116116
iterator.remove();
117-
} else if (parserContext.parseFieldMatcher().match(fieldName, FIELDDATA)) {
117+
} else if (FIELDDATA.match(fieldName)) {
118118
// for bw compat only
119119
Map<String, String> fieldDataSettings = SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata"));
120120
if (fieldDataSettings.containsKey("loading")) {

core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.Locale;
4444
import java.util.Map;
4545
import java.util.Objects;
46-
import java.util.Optional;
4746
import java.util.TreeMap;
4847

4948
/**
@@ -152,7 +151,7 @@ public static Type parse(String value, ParseFieldMatcher parseFieldMatcher) {
152151
MultiMatchQueryBuilder.Type[] values = MultiMatchQueryBuilder.Type.values();
153152
Type type = null;
154153
for (MultiMatchQueryBuilder.Type t : values) {
155-
if (parseFieldMatcher.match(value, t.parseField())) {
154+
if (t.parseField().match(value)) {
156155
type = t;
157156
break;
158157
}

core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public static MultiTermQuery.RewriteMethod parseRewriteMethod(ParseFieldMatcher
5959
if (rewriteMethod == null) {
6060
return defaultRewriteMethod;
6161
}
62-
if (matcher.match(rewriteMethod, CONSTANT_SCORE)) {
62+
if (CONSTANT_SCORE.match(rewriteMethod)) {
6363
return MultiTermQuery.CONSTANT_SCORE_REWRITE;
6464
}
65-
if (matcher.match(rewriteMethod, SCORING_BOOLEAN)) {
65+
if (SCORING_BOOLEAN.match(rewriteMethod)) {
6666
return MultiTermQuery.SCORING_BOOLEAN_REWRITE;
6767
}
68-
if (matcher.match(rewriteMethod, CONSTANT_SCORE_BOOLEAN)) {
68+
if (CONSTANT_SCORE_BOOLEAN.match(rewriteMethod)) {
6969
return MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE;
7070
}
7171

@@ -81,13 +81,13 @@ public static MultiTermQuery.RewriteMethod parseRewriteMethod(ParseFieldMatcher
8181
final int size = Integer.parseInt(rewriteMethod.substring(firstDigit));
8282
String rewriteMethodName = rewriteMethod.substring(0, firstDigit);
8383

84-
if (matcher.match(rewriteMethodName, TOP_TERMS)) {
84+
if (TOP_TERMS.match(rewriteMethodName)) {
8585
return new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(size);
8686
}
87-
if (matcher.match(rewriteMethodName, TOP_TERMS_BOOST)) {
87+
if (TOP_TERMS_BOOST.match(rewriteMethodName)) {
8888
return new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite(size);
8989
}
90-
if (matcher.match(rewriteMethodName, TOP_TERMS_BLENDED_FREQS)) {
90+
if (TOP_TERMS_BLENDED_FREQS.match(rewriteMethodName)) {
9191
return new MultiTermQuery.TopTermsBlendedFreqScoringRewrite(size);
9292
}
9393
}

core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ public static ClearIndicesCacheRequest fromRequest(final RestRequest request, Cl
8383
ParseFieldMatcher parseFieldMatcher) {
8484

8585
for (Map.Entry<String, String> entry : request.params().entrySet()) {
86-
if (parseFieldMatcher.match(entry.getKey(), Fields.QUERY)) {
86+
if (Fields.QUERY.match(entry.getKey())) {
8787
clearIndicesCacheRequest.queryCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.queryCache()));
8888
}
89-
if (parseFieldMatcher.match(entry.getKey(), Fields.REQUEST_CACHE)) {
89+
if (Fields.REQUEST_CACHE.match(entry.getKey())) {
9090
clearIndicesCacheRequest.requestCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.requestCache()));
9191
}
92-
if (parseFieldMatcher.match(entry.getKey(), Fields.FIELD_DATA)) {
92+
if (Fields.FIELD_DATA.match(entry.getKey())) {
9393
clearIndicesCacheRequest.fieldDataCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.fieldDataCache()));
9494
}
95-
if (parseFieldMatcher.match(entry.getKey(), Fields.RECYCLER)) {
95+
if (Fields.RECYCLER.match(entry.getKey())) {
9696
clearIndicesCacheRequest.recycler(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.recycler()));
9797
}
98-
if (parseFieldMatcher.match(entry.getKey(), Fields.FIELDS)) {
98+
if (Fields.FIELDS.match(entry.getKey())) {
9999
clearIndicesCacheRequest.fields(request.paramAsStringArray(entry.getKey(), clearIndicesCacheRequest.fields()));
100100
}
101101
}

core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ private static Range parseRange(XContentParser parser, QueryParseContext context
9494
if (parser.currentToken() == Token.FIELD_NAME) {
9595
continue;
9696
}
97-
if (parseFieldMatcher.match(parser.currentName(), RangeAggregator.Range.KEY_FIELD)) {
97+
if (RangeAggregator.Range.KEY_FIELD.match(parser.currentName())) {
9898
key = parser.text();
99-
} else if (parseFieldMatcher.match(parser.currentName(), RangeAggregator.Range.FROM_FIELD)) {
99+
} else if (RangeAggregator.Range.FROM_FIELD.match(parser.currentName())) {
100100
from = parser.textOrNull();
101-
} else if (parseFieldMatcher.match(parser.currentName(), RangeAggregator.Range.TO_FIELD)) {
101+
} else if (RangeAggregator.Range.TO_FIELD.match(parser.currentName())) {
102102
to = parser.textOrNull();
103-
} else if (parseFieldMatcher.match(parser.currentName(), MASK_FIELD)) {
103+
} else if (MASK_FIELD.match(parser.currentName())) {
104104
mask = parser.text();
105105
} else {
106106
throw new ParsingException(parser.getTokenLocation(), "Unexpected ip range parameter: [" + parser.currentName() + "]");

core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/GND.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public SignificanceHeuristic parse(QueryParseContext context) throws IOException
119119
boolean backgroundIsSuperset = true;
120120
XContentParser.Token token = parser.nextToken();
121121
while (!token.equals(XContentParser.Token.END_OBJECT)) {
122-
if (context.getParseFieldMatcher().match(parser.currentName(), BACKGROUND_IS_SUPERSET)) {
122+
if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
123123
parser.nextToken();
124124
backgroundIsSuperset = parser.booleanValue();
125125
} else {

core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/NXYSignificanceHeuristic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ public SignificanceHeuristic parse(QueryParseContext context)
160160
boolean backgroundIsSuperset = true;
161161
XContentParser.Token token = parser.nextToken();
162162
while (!token.equals(XContentParser.Token.END_OBJECT)) {
163-
if (context.getParseFieldMatcher().match(parser.currentName(), INCLUDE_NEGATIVES_FIELD)) {
163+
if (INCLUDE_NEGATIVES_FIELD.match(parser.currentName())) {
164164
parser.nextToken();
165165
includeNegatives = parser.booleanValue();
166-
} else if (context.getParseFieldMatcher().match(parser.currentName(), BACKGROUND_IS_SUPERSET)) {
166+
} else if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
167167
parser.nextToken();
168168
backgroundIsSuperset = parser.booleanValue();
169169
} else {

core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregationBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
643643
} else if (token.isValue()) {
644644
if (SearchSourceBuilder.SCRIPT_FIELD.match(currentFieldName)) {
645645
script = Script.parse(parser, context.getParseFieldMatcher(), context.getDefaultScriptLanguage());
646-
} else if (context.getParseFieldMatcher().match(currentFieldName,
647-
SearchSourceBuilder.IGNORE_FAILURE_FIELD)) {
646+
} else if (SearchSourceBuilder.IGNORE_FAILURE_FIELD.match(currentFieldName)) {
648647
ignoreFailure = parser.booleanValue();
649648
} else {
650649
throw new ParsingException(parser.getTokenLocation(),

core/src/main/java/org/elasticsearch/search/suggest/SuggestionBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ static SuggestionBuilder<?> fromXContent(QueryParseContext parseContext, Suggest
269269
if (token == XContentParser.Token.FIELD_NAME) {
270270
currentFieldName = parser.currentName();
271271
} else if (token.isValue()) {
272-
if (parsefieldMatcher.match(currentFieldName, TEXT_FIELD)) {
272+
if (TEXT_FIELD.match(currentFieldName)) {
273273
suggestText = parser.text();
274-
} else if (parsefieldMatcher.match(currentFieldName, PREFIX_FIELD)) {
274+
} else if (PREFIX_FIELD.match(currentFieldName)) {
275275
prefix = parser.text();
276-
} else if (parsefieldMatcher.match(currentFieldName, REGEX_FIELD)) {
276+
} else if (PREFIX_FIELD.match(currentFieldName)) {
277277
regex = parser.text();
278278
} else {
279279
throw new ParsingException(parser.getTokenLocation(), "suggestion does not support [" + currentFieldName + "]");

core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ public static LinearInterpolation innerFromXContent(QueryParseContext parseConte
143143
if (token == XContentParser.Token.FIELD_NAME) {
144144
fieldName = parser.currentName();
145145
} else if (token.isValue()) {
146-
if (matcher.match(fieldName, TRIGRAM_FIELD)) {
146+
if (TRIGRAM_FIELD.match(fieldName)) {
147147
trigramLambda = parser.doubleValue();
148148
if (trigramLambda < 0) {
149149
throw new IllegalArgumentException("trigram_lambda must be positive");
150150
}
151-
} else if (matcher.match(fieldName, BIGRAM_FIELD)) {
151+
} else if (BIGRAM_FIELD.match(fieldName)) {
152152
bigramLambda = parser.doubleValue();
153153
if (bigramLambda < 0) {
154154
throw new IllegalArgumentException("bigram_lambda must be positive");
155155
}
156-
} else if (matcher.match(fieldName, UNIGRAM_FIELD)) {
156+
} else if (UNIGRAM_FIELD.match(fieldName)) {
157157
unigramLambda = parser.doubleValue();
158158
if (unigramLambda < 0) {
159159
throw new IllegalArgumentException("unigram_lambda must be positive");

core/src/test/java/org/elasticsearch/search/aggregations/support/IncludeExcludeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ private IncludeExclude serializeMixedRegex(IncludeExclude incExc) throws IOExcep
282282
IncludeExclude exc = null;
283283
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
284284
assertEquals(XContentParser.Token.FIELD_NAME, token);
285-
if (parseFieldMatcher.match(parser.currentName(), IncludeExclude.INCLUDE_FIELD)) {
285+
if (IncludeExclude.INCLUDE_FIELD.match(parser.currentName())) {
286286
token = parser.nextToken();
287287
inc = IncludeExclude.parseInclude(parser, parseContext);
288-
} else if (parseFieldMatcher.match(parser.currentName(), IncludeExclude.EXCLUDE_FIELD)) {
288+
} else if (IncludeExclude.EXCLUDE_FIELD.match(parser.currentName())) {
289289
token = parser.nextToken();
290290
exc = IncludeExclude.parseExclude(parser, parseContext);
291291
} else {

modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,21 @@ static Script parseScript(Map<String, Object> config, ParseFieldMatcher parseFie
9999
} else {
100100
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
101101
}
102-
} else if (parseFieldMatcher.match(parameterName, ScriptType.INLINE.getParseField())) {
102+
} else if (ScriptType.INLINE.getParseField().match(parameterName)) {
103103
if (parameterValue instanceof String || parameterValue == null) {
104104
script = (String) parameterValue;
105105
type = ScriptType.INLINE;
106106
} else {
107107
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
108108
}
109-
} else if (parseFieldMatcher.match(parameterName, ScriptType.FILE.getParseField())) {
109+
} else if (ScriptType.FILE.getParseField().match(parameterName)) {
110110
if (parameterValue instanceof String || parameterValue == null) {
111111
script = (String) parameterValue;
112112
type = ScriptType.FILE;
113113
} else {
114114
throw new ElasticsearchParseException("Value must be of type String: [" + parameterName + "]");
115115
}
116-
} else if (parseFieldMatcher.match(parameterName, ScriptType.STORED.getParseField())) {
116+
} else if (ScriptType.STORED.getParseField().match(parameterName)) {
117117
if (parameterValue instanceof String || parameterValue == null) {
118118
script = (String) parameterValue;
119119
type = ScriptType.STORED;

0 commit comments

Comments
 (0)