Skip to content

Commit 1eeab39

Browse files
authored
Simplify TextSearchInfo handling in MappedFieldType (#135617)
The vast majority of field types use TextSearchInfo.NONE, and most of the rest extend TermBasedFieldType. Rather than forcing all field types to include TextSearchInfo as part of a constructor call, we instead have a default method on the base class, a constructor parameter for TermBasedFieldType, and method overrides for the few field types left over.
1 parent e0c4132 commit 1eeab39

File tree

44 files changed

+120
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+120
-84
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.index.mapper.MappedFieldType;
2424
import org.elasticsearch.index.mapper.MapperBuilderContext;
2525
import org.elasticsearch.index.mapper.SourceValueFetcher;
26-
import org.elasticsearch.index.mapper.TextSearchInfo;
2726
import org.elasticsearch.index.mapper.ValueFetcher;
2827
import org.elasticsearch.index.query.SearchExecutionContext;
2928
import org.elasticsearch.xcontent.XContentBuilder;
@@ -114,7 +113,7 @@ public static final class RankFeatureFieldType extends MappedFieldType {
114113
private final Float nullValue;
115114

116115
public RankFeatureFieldType(String name, Map<String, String> meta, boolean positiveScoreImpact, Float nullValue) {
117-
super(name, true, false, false, TextSearchInfo.NONE, meta);
116+
super(name, true, false, false, meta);
118117
this.positiveScoreImpact = positiveScoreImpact;
119118
this.nullValue = nullValue;
120119
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.lucene.search.Query;
1414
import org.elasticsearch.index.mapper.MappedFieldType;
1515
import org.elasticsearch.index.mapper.MetadataFieldMapper;
16-
import org.elasticsearch.index.mapper.TextSearchInfo;
1716
import org.elasticsearch.index.mapper.ValueFetcher;
1817
import org.elasticsearch.index.query.SearchExecutionContext;
1918

@@ -38,7 +37,7 @@ public static final class RankFeatureMetaFieldType extends MappedFieldType {
3837

3938
// made visible for tests
4039
RankFeatureMetaFieldType() {
41-
super(NAME, false, false, false, TextSearchInfo.NONE, Collections.emptyMap());
40+
super(NAME, false, false, false, Collections.emptyMap());
4241
}
4342

4443
@Override

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static final class RankFeaturesFieldType extends MappedFieldType {
8080
private final boolean positiveScoreImpact;
8181

8282
public RankFeaturesFieldType(String name, Map<String, String> meta, boolean positiveScoreImpact) {
83-
super(name, true, false, false, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
83+
super(name, true, false, false, meta);
8484
this.positiveScoreImpact = positiveScoreImpact;
8585
}
8686

@@ -104,6 +104,11 @@ public ValueFetcher valueFetcher(SearchExecutionContext context, String format)
104104
return SourceValueFetcher.identity(name(), context, format);
105105
}
106106

107+
@Override
108+
public TextSearchInfo getTextSearchInfo() {
109+
return TextSearchInfo.SIMPLE_MATCH_ONLY;
110+
}
111+
107112
@Override
108113
public Query termQuery(Object value, SearchExecutionContext context) {
109114
return FeatureField.newLinearQuery(name(), indexedValueForSearch(value), DEFAULT_BOOST);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public ScaledFloatFieldType(
284284
boolean coerce,
285285
boolean isSyntheticSource
286286
) {
287-
super(name, indexed, stored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
287+
super(name, indexed, stored, hasDocValues, meta);
288288
this.scalingFactor = scalingFactor;
289289
this.nullValue = nullValue;
290290
this.metricType = metricType;
@@ -320,6 +320,11 @@ public boolean isSearchable() {
320320
return isIndexed() || hasDocValues();
321321
}
322322

323+
@Override
324+
public TextSearchInfo getTextSearchInfo() {
325+
return TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS;
326+
}
327+
323328
@Override
324329
public Query termQuery(Object value, SearchExecutionContext context) {
325330
failIfNotIndexedNorDocValuesFallback(context);

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.elasticsearch.index.mapper.RangeFieldMapper;
5656
import org.elasticsearch.index.mapper.RangeType;
5757
import org.elasticsearch.index.mapper.SourceValueFetcher;
58-
import org.elasticsearch.index.mapper.TextSearchInfo;
5958
import org.elasticsearch.index.mapper.ValueFetcher;
6059
import org.elasticsearch.index.query.FilteredSearchExecutionContext;
6160
import org.elasticsearch.index.query.QueryBuilder;
@@ -240,7 +239,7 @@ static class PercolatorFieldType extends MappedFieldType {
240239
boolean mapUnmappedFieldsAsText;
241240

242241
private PercolatorFieldType(String name, Map<String, String> meta) {
243-
super(name, false, false, false, TextSearchInfo.NONE, meta);
242+
super(name, false, false, false, meta);
244243
}
245244

246245
@Override

plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.index.mapper.MappedFieldType;
2424
import org.elasticsearch.index.mapper.MapperBuilderContext;
2525
import org.elasticsearch.index.mapper.SourceValueFetcher;
26-
import org.elasticsearch.index.mapper.TextSearchInfo;
2726
import org.elasticsearch.index.mapper.ValueFetcher;
2827
import org.elasticsearch.index.query.SearchExecutionContext;
2928
import org.elasticsearch.script.field.murmur3.Murmur3DocValueField;
@@ -69,7 +68,7 @@ public Murmur3FieldMapper build(MapperBuilderContext context) {
6968
public static class Murmur3FieldType extends MappedFieldType {
7069

7170
private Murmur3FieldType(String name, boolean isStored, Map<String, String> meta) {
72-
super(name, false, isStored, true, TextSearchInfo.NONE, meta);
71+
super(name, false, isStored, true, meta);
7372
}
7473

7574
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected AbstractGeometryFieldType(
143143
T nullValue,
144144
Map<String, String> meta
145145
) {
146-
super(name, indexed, stored, hasDocValues, TextSearchInfo.NONE, meta);
146+
super(name, indexed, stored, hasDocValues, meta);
147147
this.nullValue = nullValue;
148148
this.geometryParser = geometryParser;
149149
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected AbstractScriptFieldType(
6262
Map<String, String> meta,
6363
boolean isParsedFromSource
6464
) {
65-
super(name, false, false, false, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
65+
super(name, false, false, false, meta);
6666
this.factory = factory;
6767
this.script = Objects.requireNonNull(script);
6868
this.isResultDeterministic = isResultDeterministic;
@@ -79,6 +79,11 @@ public final boolean isAggregatable() {
7979
return true;
8080
}
8181

82+
@Override
83+
public TextSearchInfo getTextSearchInfo() {
84+
return TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS;
85+
}
86+
8287
@Override
8388
public final Query rangeQuery(
8489
Object lowerTerm,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public BinaryFieldMapper build(MapperBuilderContext context) {
8383

8484
public static final class BinaryFieldType extends MappedFieldType {
8585
private BinaryFieldType(String name, boolean isStored, boolean hasDocValues, Map<String, String> meta) {
86-
super(name, false, isStored, hasDocValues, TextSearchInfo.NONE, meta);
86+
super(name, false, isStored, hasDocValues, meta);
8787
}
8888

8989
public BinaryFieldType(String name) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class ConstantFieldType extends MappedFieldType {
3838

3939
@SuppressWarnings("this-escape")
4040
public ConstantFieldType(String name, Map<String, String> meta) {
41-
super(name, true, false, true, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
41+
super(name, true, false, true, meta);
4242
assert isSearchable();
4343
}
4444

@@ -47,6 +47,11 @@ public final boolean isAggregatable() {
4747
return true;
4848
}
4949

50+
@Override
51+
public TextSearchInfo getTextSearchInfo() {
52+
return TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS;
53+
}
54+
5055
/**
5156
* Return whether the constant value of this field matches the provided {@code pattern}
5257
* as documented in {@link Regex#simpleMatch}.

0 commit comments

Comments
 (0)