Skip to content

Commit cd0a375

Browse files
authored
Remove unused query methods from MappedFieldType. (#30987)
* Remove MappedFieldType#nullValueQuery, as it is now unused. * Remove MappedFieldType#queryStringTermQuery, as it is never overridden.
1 parent 4f66b9a commit cd0a375

File tree

10 files changed

+15
-98
lines changed

10 files changed

+15
-98
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/FeatureFieldMapper.java

-8
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,6 @@ public Query existsQuery(QueryShardContext context) {
163163
return new TermQuery(new Term("_feature", name()));
164164
}
165165

166-
@Override
167-
public Query nullValueQuery() {
168-
if (nullValue() == null) {
169-
return null;
170-
}
171-
return termQuery(nullValue(), null);
172-
}
173-
174166
@Override
175167
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
176168
failIfNoDocValues();

plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java

-8
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ public Query existsQuery(QueryShardContext context) {
135135
}
136136
}
137137

138-
@Override
139-
public Query nullValueQuery() {
140-
if (nullValue() == null) {
141-
return null;
142-
}
143-
return termQuery(nullValue(), null);
144-
}
145-
146138
@Override
147139
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
148140
failIfNoDocValues();

server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java

+1-20
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@
1919

2020
package org.apache.lucene.queries;
2121

22-
import org.apache.lucene.index.Term;
23-
import org.apache.lucene.index.TermContext;
2422
import org.apache.lucene.search.BooleanClause.Occur;
25-
import org.apache.lucene.search.Query;
2623
import org.elasticsearch.common.lucene.search.Queries;
27-
import org.elasticsearch.index.mapper.MappedFieldType;
2824

2925
/**
3026
* Extended version of {@link CommonTermsQuery} that allows to pass in a
@@ -33,11 +29,8 @@
3329
*/
3430
public class ExtendedCommonTermsQuery extends CommonTermsQuery {
3531

36-
private final MappedFieldType fieldType;
37-
38-
public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency, MappedFieldType fieldType) {
32+
public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency) {
3933
super(highFreqOccur, lowFreqOccur, maxTermFrequency);
40-
this.fieldType = fieldType;
4134
}
4235

4336
private String lowFreqMinNumShouldMatchSpec;
@@ -80,16 +73,4 @@ public float getMaxTermFrequency() {
8073
return this.maxTermFrequency;
8174
}
8275

83-
@Override
84-
protected Query newTermQuery(Term term, TermContext context) {
85-
if (fieldType == null) {
86-
return super.newTermQuery(term, context);
87-
}
88-
final Query query = fieldType.queryStringTermQuery(term);
89-
if (query == null) {
90-
return super.newTermQuery(term, context);
91-
} else {
92-
return query;
93-
}
94-
}
9576
}

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

-8
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,6 @@ public Query existsQuery(QueryShardContext context) {
223223
}
224224
}
225225

226-
@Override
227-
public Query nullValueQuery() {
228-
if (nullValue() == null) {
229-
return null;
230-
}
231-
return termQuery(nullValue(), null);
232-
}
233-
234226
@Override
235227
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
236228
failIfNoDocValues();

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

-13
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,6 @@ public Query regexpQuery(String value, int flags, int maxDeterminizedStates, @Nu
351351
throw new QueryShardException(context, "Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]");
352352
}
353353

354-
public Query nullValueQuery() {
355-
if (nullValue == null) {
356-
return null;
357-
}
358-
return new ConstantScoreQuery(termQuery(nullValue, null));
359-
}
360-
361354
public abstract Query existsQuery(QueryShardContext context);
362355

363356
/**
@@ -382,12 +375,6 @@ public Relation isFieldWithinQuery(
382375
return Relation.INTERSECTS;
383376
}
384377

385-
/** A term query to use when parsing a query string. Can return {@code null}. */
386-
@Nullable
387-
public Query queryStringTermQuery(Term term) {
388-
return null;
389-
}
390-
391378
/** @throws IllegalArgumentException if the fielddata is not supported on this type.
392379
* An IllegalArgumentException is needed in order to return an http error 400
393380
* when this error occurs in a request. see: {@link org.elasticsearch.ExceptionsHelper#status}

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.lucene.analysis.TokenFilter;
2525
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter;
2626
import org.apache.lucene.document.Field;
27-
import org.apache.lucene.document.FieldType;
2827
import org.apache.lucene.index.IndexOptions;
2928
import org.apache.lucene.index.IndexableField;
3029
import org.apache.lucene.index.Term;
@@ -471,14 +470,6 @@ public Query existsQuery(QueryShardContext context) {
471470
}
472471
}
473472

474-
@Override
475-
public Query nullValueQuery() {
476-
if (nullValue() == null) {
477-
return null;
478-
}
479-
return termQuery(nullValue(), null);
480-
}
481-
482473
@Override
483474
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
484475
if (fielddata == false) {

server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
371371
Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur();
372372
Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur();
373373

374-
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur,
375-
cutoffFrequency, fieldType);
374+
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency);
376375
return parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);
377376
}
378377

server/src/main/java/org/elasticsearch/index/search/MatchQuery.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
package org.elasticsearch.index.search;
2121

2222
import org.apache.lucene.analysis.Analyzer;
23-
import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute;
2423
import org.apache.lucene.analysis.TokenStream;
24+
import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute;
2525
import org.apache.lucene.index.IndexOptions;
2626
import org.apache.lucene.index.Term;
2727
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
2828
import org.apache.lucene.search.BooleanClause;
2929
import org.apache.lucene.search.BooleanClause.Occur;
3030
import org.apache.lucene.search.BooleanQuery;
3131
import org.apache.lucene.search.BoostQuery;
32-
import org.apache.lucene.search.DisjunctionMaxQuery;
3332
import org.apache.lucene.search.FuzzyQuery;
3433
import org.apache.lucene.search.MultiPhraseQuery;
3534
import org.apache.lucene.search.MultiTermQuery;
@@ -283,7 +282,7 @@ public Query parse(Type type, String fieldName, Object value) throws IOException
283282
if (commonTermsCutoff == null) {
284283
query = builder.createBooleanQuery(field, value.toString(), occur);
285284
} else {
286-
query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff, fieldType);
285+
query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff);
287286
}
288287
break;
289288
case PHRASE:
@@ -463,20 +462,23 @@ private Query toSpanQueryPrefix(SpanQuery query, float boost) {
463462
}
464463
}
465464

466-
public Query createCommonTermsQuery(String field, String queryText, Occur highFreqOccur, Occur lowFreqOccur, float
467-
maxTermFrequency, MappedFieldType fieldType) {
465+
public Query createCommonTermsQuery(String field, String queryText,
466+
Occur highFreqOccur,
467+
Occur lowFreqOccur,
468+
float maxTermFrequency) {
468469
Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur);
469470
if (booleanQuery != null && booleanQuery instanceof BooleanQuery) {
470471
BooleanQuery bq = (BooleanQuery) booleanQuery;
471-
return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency, fieldType);
472+
return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency);
472473
}
473474
return booleanQuery;
474475
}
475476

476-
private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, Occur highFreqOccur, Occur lowFreqOccur, float
477-
maxTermFrequency, MappedFieldType fieldType) {
478-
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency,
479-
fieldType);
477+
private Query boolToExtendedCommonTermsQuery(BooleanQuery bq,
478+
Occur highFreqOccur,
479+
Occur lowFreqOccur,
480+
float maxTermFrequency) {
481+
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency);
480482
for (BooleanClause clause : bq.clauses()) {
481483
if (!(clause.getQuery() instanceof TermQuery)) {
482484
return bq;

server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java

-11
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,6 @@ private Map<String, Float> extractMultiFields(String field, boolean quoted) {
272272
}
273273
}
274274

275-
@Override
276-
protected Query newTermQuery(Term term) {
277-
if (currentFieldType != null) {
278-
Query termQuery = currentFieldType.queryStringTermQuery(term);
279-
if (termQuery != null) {
280-
return termQuery;
281-
}
282-
}
283-
return super.newTermQuery(term);
284-
}
285-
286275
@Override
287276
protected Query newMatchAllDocsQuery() {
288277
return Queries.newMatchAllQuery();

server/src/test/java/org/elasticsearch/index/mapper/FakeStringFieldMapper.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ public String typeName() {
105105
return CONTENT_TYPE;
106106
}
107107

108-
@Override
109-
public Query nullValueQuery() {
110-
if (nullValue() == null) {
111-
return null;
112-
}
113-
return termQuery(nullValue(), null);
114-
}
115-
116108
@Override
117109
public Query existsQuery(QueryShardContext context) {
118110
if (hasDocValues()) {
@@ -136,7 +128,7 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
136128
} else {
137129
value = context.parser().textOrNull();
138130
}
139-
131+
140132
if (value == null) {
141133
return;
142134
}

0 commit comments

Comments
 (0)