MappedFieldType no longer requires equals/hashCode/clone (#59212)

With the removal of mapping types and the immutability of FieldTypeLookup in #58162, we no longer
have any cause to compare MappedFieldType instances. This means that we can remove all equals
and hashCode implementations, and in addition we no longer need the clone implementations which
were required for equals/hashcode testing. This greatly simplifies implementing new MappedFieldTypes,
which will be particularly useful for the runtime fields project.
This commit is contained in:
Alan Woodward 2020-07-09 21:01:29 +01:00 committed by Alan Woodward
parent 54483394ae
commit f4caadd239
88 changed files with 71 additions and 1334 deletions

View File

@ -103,15 +103,6 @@ public class RankFeatureFieldMapper extends FieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
protected RankFeatureFieldType(RankFeatureFieldType ref) {
super(ref);
this.positiveScoreImpact = ref.positiveScoreImpact;
}
public RankFeatureFieldType clone() {
return new RankFeatureFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -92,15 +92,6 @@ public class RankFeatureMetaFieldMapper extends MetadataFieldMapper {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap()); super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
} }
protected RankFeatureMetaFieldType(RankFeatureMetaFieldType ref) {
super(ref);
}
@Override
public RankFeatureMetaFieldType clone() {
return new RankFeatureMetaFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -80,14 +80,6 @@ public class RankFeaturesFieldMapper extends FieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
protected RankFeaturesFieldType(RankFeaturesFieldType ref) {
super(ref);
}
public RankFeaturesFieldType clone() {
return new RankFeaturesFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -193,20 +193,10 @@ public class ScaledFloatFieldMapper extends FieldMapper {
this(name, true, true, Collections.emptyMap(), scalingFactor); this(name, true, true, Collections.emptyMap(), scalingFactor);
} }
ScaledFloatFieldType(ScaledFloatFieldType other) {
super(other);
this.scalingFactor = other.scalingFactor;
}
public double getScalingFactor() { public double getScalingFactor() {
return scalingFactor; return scalingFactor;
} }
@Override
public MappedFieldType clone() {
return new ScaledFloatFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
@ -310,19 +300,6 @@ public class ScaledFloatFieldMapper extends FieldMapper {
} }
} }
@Override
public boolean equals(Object o) {
if (super.equals(o) == false) {
return false;
}
return scalingFactor == ((ScaledFloatFieldType) o).scalingFactor;
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Double.hashCode(scalingFactor);
}
/** /**
* Parses input value and multiplies it with the scaling factor. * Parses input value and multiplies it with the scaling factor.
* Uses the round-trip of creating a {@link BigDecimal} from the stringified {@code double} * Uses the round-trip of creating a {@link BigDecimal} from the stringified {@code double}

View File

@ -252,22 +252,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
new TextSearchInfo(fieldType, similarity, searchAnalyzer, searchQuoteAnalyzer), meta); new TextSearchInfo(fieldType, similarity, searchAnalyzer, searchQuoteAnalyzer), meta);
} }
SearchAsYouTypeFieldType(SearchAsYouTypeFieldType other) {
super(other);
if (other.prefixField != null) {
this.prefixField = other.prefixField.clone();
}
if (other.shingleFields != null) {
this.shingleFields = new ShingleFieldType[other.shingleFields.length];
for (int i = 0; i < this.shingleFields.length; i++) {
if (other.shingleFields[i] != null) {
this.shingleFields[i] = other.shingleFields[i].clone();
}
}
}
}
public void setPrefixField(PrefixFieldType prefixField) { public void setPrefixField(PrefixFieldType prefixField) {
this.prefixField = prefixField; this.prefixField = prefixField;
} }
@ -276,11 +260,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
this.shingleFields = shingleFields; this.shingleFields = shingleFields;
} }
@Override
public MappedFieldType clone() {
return new SearchAsYouTypeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
@ -361,27 +340,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
return spanMulti; return spanMulti;
} }
} }
@Override
public boolean equals(Object otherObject) {
if (this == otherObject) {
return true;
}
if (otherObject == null || getClass() != otherObject.getClass()) {
return false;
}
if (!super.equals(otherObject)) {
return false;
}
final SearchAsYouTypeFieldType other = (SearchAsYouTypeFieldType) otherObject;
return Objects.equals(prefixField, other.prefixField) &&
Arrays.equals(shingleFields, other.shingleFields);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), prefixField, Arrays.hashCode(shingleFields));
}
} }
/** /**
@ -401,13 +359,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
this.parentField = parentField; this.parentField = parentField;
} }
PrefixFieldType(PrefixFieldType other) {
super(other);
this.minChars = other.minChars;
this.maxChars = other.maxChars;
this.parentField = other.parentField;
}
boolean termLengthWithinBounds(int length) { boolean termLengthWithinBounds(int length) {
return length >= minChars - 1 && length <= maxChars; return length >= minChars - 1 && length <= maxChars;
} }
@ -431,11 +382,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
.build(); .build();
} }
@Override
public PrefixFieldType clone() {
return new PrefixFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return "prefix"; return "prefix";
@ -450,27 +396,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
public Query existsQuery(QueryShardContext context) { public Query existsQuery(QueryShardContext context) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
PrefixFieldType that = (PrefixFieldType) o;
return minChars == that.minChars &&
maxChars == that.maxChars;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), minChars, maxChars);
}
} }
static final class PrefixFieldMapper extends FieldMapper { static final class PrefixFieldMapper extends FieldMapper {
@ -552,23 +477,10 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
this.shingleSize = shingleSize; this.shingleSize = shingleSize;
} }
ShingleFieldType(ShingleFieldType other) {
super(other);
this.shingleSize = other.shingleSize;
if (other.prefixFieldType != null) {
this.prefixFieldType = other.prefixFieldType.clone();
}
}
void setPrefixFieldType(PrefixFieldType prefixFieldType) { void setPrefixFieldType(PrefixFieldType prefixFieldType) {
this.prefixFieldType = prefixFieldType; this.prefixFieldType = prefixFieldType;
} }
@Override
public ShingleFieldType clone() {
return new ShingleFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
@ -629,27 +541,6 @@ public class SearchAsYouTypeFieldMapper extends FieldMapper {
return spanMulti; return spanMulti;
} }
} }
@Override
public boolean equals(Object otherObject) {
if (this == otherObject) {
return true;
}
if (otherObject == null || getClass() != otherObject.getClass()) {
return false;
}
if (!super.equals(otherObject)) {
return false;
}
final ShingleFieldType other = (ShingleFieldType) otherObject;
return shingleSize == other.shingleSize
&& Objects.equals(prefixFieldType, other.prefixFieldType);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), shingleSize, prefixFieldType);
}
} }
private final int maxShingleSize; private final int maxShingleSize;

View File

@ -20,14 +20,8 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class RankFeatureFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class RankFeatureFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new RankFeatureFieldMapper.RankFeatureFieldType(name, meta, true);
}
public void testIsAggregatable() { public void testIsAggregatable() {
MappedFieldType fieldType = new RankFeatureFieldMapper.RankFeatureFieldType("field", Collections.emptyMap(), true); MappedFieldType fieldType = new RankFeatureFieldMapper.RankFeatureFieldType("field", Collections.emptyMap(), true);

View File

@ -20,17 +20,11 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class RankFeaturesFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class RankFeaturesFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new RankFeaturesFieldMapper.RankFeaturesFieldType(name, meta);
}
public void testIsAggregatable() { public void testIsAggregatable() {
MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap()); MappedFieldType fieldType = new RankFeaturesFieldMapper.RankFeaturesFieldType("field", Collections.emptyMap());
assertFalse(fieldType.isAggregatable()); assertFalse(fieldType.isAggregatable());
} }
} }

View File

@ -40,14 +40,9 @@ import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
public class ScaledFloatFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class ScaledFloatFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new ScaledFloatFieldMapper.ScaledFloatFieldType(name, true, true, meta, 100);
}
public void testTermQuery() { public void testTermQuery() {
ScaledFloatFieldMapper.ScaledFloatFieldType ft ScaledFloatFieldMapper.ScaledFloatFieldType ft

View File

@ -35,13 +35,12 @@ import org.elasticsearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouType
import org.elasticsearch.index.mapper.SearchAsYouTypeFieldMapper.ShingleFieldType; import org.elasticsearch.index.mapper.SearchAsYouTypeFieldMapper.ShingleFieldType;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE; import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase {
private static final String NAME = "a_field"; private static final String NAME = "a_field";
private static final FieldType UNSEARCHABLE = new FieldType(); private static final FieldType UNSEARCHABLE = new FieldType();
@ -50,10 +49,9 @@ public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase<MappedField
UNSEARCHABLE.freeze(); UNSEARCHABLE.freeze();
} }
@Override protected SearchAsYouTypeFieldType createFieldType() {
protected SearchAsYouTypeFieldType createDefaultFieldType(String name, Map<String, String> meta) { final SearchAsYouTypeFieldType fieldType = new SearchAsYouTypeFieldType(NAME, Defaults.FIELD_TYPE, null,
final SearchAsYouTypeFieldType fieldType Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER, Collections.emptyMap());
= new SearchAsYouTypeFieldType(name, Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER, meta);
fieldType.setPrefixField(new PrefixFieldType(NAME, TextSearchInfo.SIMPLE_MATCH_ONLY, Defaults.MIN_GRAM, Defaults.MAX_GRAM)); fieldType.setPrefixField(new PrefixFieldType(NAME, TextSearchInfo.SIMPLE_MATCH_ONLY, Defaults.MIN_GRAM, Defaults.MAX_GRAM));
fieldType.setShingleFields(new ShingleFieldType[] { fieldType.setShingleFields(new ShingleFieldType[] {
new ShingleFieldType(fieldType.name(), 2, TextSearchInfo.SIMPLE_MATCH_ONLY) new ShingleFieldType(fieldType.name(), 2, TextSearchInfo.SIMPLE_MATCH_ONLY)
@ -62,7 +60,7 @@ public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase<MappedField
} }
public void testTermQuery() { public void testTermQuery() {
final MappedFieldType fieldType = createDefaultFieldType(NAME, Collections.emptyMap()); final MappedFieldType fieldType = createFieldType();
assertThat(fieldType.termQuery("foo", null), equalTo(new TermQuery(new Term(NAME, "foo")))); assertThat(fieldType.termQuery("foo", null), equalTo(new TermQuery(new Term(NAME, "foo"))));
@ -73,7 +71,7 @@ public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase<MappedField
} }
public void testTermsQuery() { public void testTermsQuery() {
final MappedFieldType fieldType = createDefaultFieldType(NAME, Collections.emptyMap()); final MappedFieldType fieldType = createFieldType();
assertThat(fieldType.termsQuery(asList("foo", "bar"), null), assertThat(fieldType.termsQuery(asList("foo", "bar"), null),
equalTo(new TermInSetQuery(NAME, asList(new BytesRef("foo"), new BytesRef("bar"))))); equalTo(new TermInSetQuery(NAME, asList(new BytesRef("foo"), new BytesRef("bar")))));
@ -86,7 +84,7 @@ public class SearchAsYouTypeFieldTypeTests extends FieldTypeTestCase<MappedField
} }
public void testPrefixQuery() { public void testPrefixQuery() {
final SearchAsYouTypeFieldType fieldType = createDefaultFieldType(NAME, Collections.emptyMap()); final SearchAsYouTypeFieldType fieldType = createFieldType();
// this term should be a length that can be rewriteable to a term query on the prefix field // this term should be a length that can be rewriteable to a term query on the prefix field
final String withinBoundsTerm = "foo"; final String withinBoundsTerm = "foo";

View File

@ -82,15 +82,6 @@ public class MetaJoinFieldMapper extends FieldMapper {
this.joinField = joinField; this.joinField = joinField;
} }
protected MetaJoinFieldType(MetaJoinFieldType ref) {
super(ref);
this.joinField = ref.joinField;
}
public MetaJoinFieldType clone() {
return new MetaJoinFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -100,14 +100,6 @@ public final class ParentIdFieldMapper extends FieldMapper {
setEagerGlobalOrdinals(eagerGlobalOrdinals); setEagerGlobalOrdinals(eagerGlobalOrdinals);
} }
protected ParentIdFieldType(ParentIdFieldType ref) {
super(ref);
}
public ParentIdFieldType clone() {
return new ParentIdFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -210,14 +210,6 @@ public final class ParentJoinFieldMapper extends FieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
protected JoinFieldType(JoinFieldType ref) {
super(ref);
}
public JoinFieldType clone() {
return new JoinFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -203,21 +203,6 @@ public class PercolatorFieldMapper extends FieldMapper {
super(name, false, false, TextSearchInfo.NONE, meta); super(name, false, false, TextSearchInfo.NONE, meta);
} }
PercolatorFieldType(PercolatorFieldType ref) {
super(ref);
queryTermsField = ref.queryTermsField;
extractionResultField = ref.extractionResultField;
queryBuilderField = ref.queryBuilderField;
rangeField = ref.rangeField;
minimumShouldMatchField = ref.minimumShouldMatchField;
mapUnmappedFieldsAsText = ref.mapUnmappedFieldsAsText;
}
@Override
public MappedFieldType clone() {
return new PercolatorFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -86,26 +86,6 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper {
this(name, true, true, collator, Collections.emptyMap()); this(name, true, true, collator, Collections.emptyMap());
} }
protected CollationFieldType(CollationFieldType ref) {
super(ref);
this.collator = ref.collator;
}
@Override
public CollationFieldType clone() {
return new CollationFieldType(this);
}
@Override
public boolean equals(Object o) {
return super.equals(o) && Objects.equals(collator, ((CollationFieldType) o).collator);
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(collator);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -37,17 +37,11 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class CollationFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class CollationFieldTypeTests extends FieldTypeTestCase{
private static final Collator DEFAULT_COLLATOR = Collator.getInstance(ULocale.ROOT).freeze(); private static final Collator DEFAULT_COLLATOR = Collator.getInstance(ULocale.ROOT).freeze();
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new CollationFieldType(name, true, true, DEFAULT_COLLATOR, meta);
}
public void testIsFieldWithinQuery() throws IOException { public void testIsFieldWithinQuery() throws IOException {
CollationFieldType ft = new CollationFieldType("field", DEFAULT_COLLATOR); CollationFieldType ft = new CollationFieldType("field", DEFAULT_COLLATOR);
// current impl ignores args and shourd always return INTERSECTS // current impl ignores args and shourd always return INTERSECTS

View File

@ -521,10 +521,6 @@ public class AnnotatedTextFieldMapper extends FieldMapper {
super(name, true, meta); super(name, true, meta);
} }
protected AnnotatedTextFieldType(AnnotatedTextFieldType ref) {
super(ref);
}
public void setIndexAnalyzer(NamedAnalyzer delegate, int positionIncrementGap) { public void setIndexAnalyzer(NamedAnalyzer delegate, int positionIncrementGap) {
if(delegate.analyzer() instanceof AnnotationAnalyzerWrapper){ if(delegate.analyzer() instanceof AnnotationAnalyzerWrapper){
// Already wrapped the Analyzer with an AnnotationAnalyzer // Already wrapped the Analyzer with an AnnotationAnalyzer
@ -536,10 +532,6 @@ public class AnnotatedTextFieldMapper extends FieldMapper {
} }
} }
public AnnotatedTextFieldType clone() {
return new AnnotatedTextFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -29,16 +29,11 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class AnnotatedTextFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class AnnotatedTextFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new AnnotatedTextFieldMapper.AnnotatedTextFieldType(name, meta);
}
public void testIntervals() throws IOException { public void testIntervals() throws IOException {
MappedFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); MappedFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap());
NamedAnalyzer a = new NamedAnalyzer("name", AnalyzerScope.INDEX, new StandardAnalyzer()); NamedAnalyzer a = new NamedAnalyzer("name", AnalyzerScope.INDEX, new StandardAnalyzer());
IntervalsSource source = ft.intervals("Donald Trump", 0, true, a, false); IntervalsSource source = ft.intervals("Donald Trump", 0, true, a, false);
assertEquals(Intervals.phrase(Intervals.term("donald"), Intervals.term("trump")), source); assertEquals(Intervals.phrase(Intervals.term("donald"), Intervals.term("trump")), source);

View File

@ -96,20 +96,11 @@ public class Murmur3FieldMapper extends FieldMapper {
super(name, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); super(name, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
} }
protected Murmur3FieldType(Murmur3FieldType ref) {
super(ref);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
} }
@Override
public Murmur3FieldType clone() {
return new Murmur3FieldType(this);
}
@Override @Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues(); failIfNoDocValues();

View File

@ -191,10 +191,6 @@ public abstract class AbstractGeometryFieldMapper<Parsed, Processed> extends Fie
super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
} }
protected AbstractGeometryFieldType(AbstractGeometryFieldType ref) {
super(ref);
}
public void setGeometryQueryBuilder(QueryProcessor geometryQueryBuilder) { public void setGeometryQueryBuilder(QueryProcessor geometryQueryBuilder) {
this.geometryQueryBuilder = geometryQueryBuilder; this.geometryQueryBuilder = geometryQueryBuilder;
} }

View File

@ -117,10 +117,6 @@ public abstract class AbstractPointGeometryFieldMapper<Parsed, Processed> extend
protected AbstractPointGeometryFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) { protected AbstractPointGeometryFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, meta); super(name, indexed, hasDocValues, meta);
} }
protected AbstractPointGeometryFieldType(AbstractPointGeometryFieldType ref) {
super(ref);
}
} }
protected AbstractPointGeometryFieldMapper(String simpleName, FieldType fieldType, MappedFieldType mappedFieldType, protected AbstractPointGeometryFieldMapper(String simpleName, FieldType fieldType, MappedFieldType mappedFieldType,

View File

@ -33,7 +33,6 @@ import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* Base class for {@link GeoShapeFieldMapper} and {@link LegacyGeoShapeFieldMapper} * Base class for {@link GeoShapeFieldMapper} and {@link LegacyGeoShapeFieldMapper}
@ -162,23 +161,6 @@ public abstract class AbstractShapeGeometryFieldMapper<Parsed, Processed> extend
super(name, isSearchable, hasDocValues, meta); super(name, isSearchable, hasDocValues, meta);
} }
protected AbstractShapeGeometryFieldType(AbstractShapeGeometryFieldType ref) {
super(ref);
this.orientation = ref.orientation;
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
AbstractShapeGeometryFieldType that = (AbstractShapeGeometryFieldType) o;
return orientation == that.orientation;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), orientation);
}
public Orientation orientation() { return this.orientation; } public Orientation orientation() { return this.orientation; }
public void setOrientation(Orientation orientation) { public void setOrientation(Orientation orientation) {

View File

@ -102,15 +102,6 @@ public class AllFieldMapper extends MetadataFieldMapper {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap()); super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
} }
protected AllFieldType(AllFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new AllFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -103,16 +103,6 @@ public class BinaryFieldMapper extends ParametrizedFieldMapper {
this(name, true, Collections.emptyMap()); this(name, true, Collections.emptyMap());
} }
protected BinaryFieldType(BinaryFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new BinaryFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -123,15 +123,6 @@ public class BooleanFieldMapper extends ParametrizedFieldMapper {
this(name, true, true, Collections.emptyMap()); this(name, true, true, Collections.emptyMap());
} }
protected BooleanFieldType(BooleanFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new BooleanFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -59,7 +59,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.index.mapper.TypeParsers.parseMultiField; import static org.elasticsearch.index.mapper.TypeParsers.parseMultiField;
@ -208,13 +207,6 @@ public class CompletionFieldMapper extends FieldMapper {
Collections.emptyMap()); Collections.emptyMap());
} }
private CompletionFieldType(CompletionFieldType ref) {
super(ref);
this.contextMappings = ref.contextMappings;
this.preserveSep = ref.preserveSep;
this.preservePositionIncrements = ref.preservePositionIncrements;
}
public void setPreserveSep(boolean preserveSep) { public void setPreserveSep(boolean preserveSep) {
this.preserveSep = preserveSep; this.preserveSep = preserveSep;
} }
@ -303,33 +295,6 @@ public class CompletionFieldMapper extends FieldMapper {
unicodeAware, maxExpansions); unicodeAware, maxExpansions);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
CompletionFieldType that = (CompletionFieldType) o;
if (preserveSep != that.preserveSep) return false;
if (preservePositionIncrements != that.preservePositionIncrements) return false;
return Objects.equals(contextMappings, that.contextMappings);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(),
preserveSep,
preservePositionIncrements,
contextMappings);
}
@Override
public CompletionFieldType clone() {
return new CompletionFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -45,10 +45,6 @@ public abstract class ConstantFieldType extends MappedFieldType {
super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
} }
public ConstantFieldType(ConstantFieldType other) {
super(other);
}
@Override @Override
public final boolean isSearchable() { public final boolean isSearchable() {
return true; return true;

View File

@ -317,32 +317,6 @@ public final class DateFieldMapper extends FieldMapper {
this(name, true, true, DEFAULT_DATE_TIME_FORMATTER, Resolution.MILLISECONDS, Collections.emptyMap()); this(name, true, true, DEFAULT_DATE_TIME_FORMATTER, Resolution.MILLISECONDS, Collections.emptyMap());
} }
DateFieldType(DateFieldType other) {
super(other);
this.dateTimeFormatter = other.dateTimeFormatter;
this.dateMathParser = other.dateMathParser;
this.resolution = other.resolution;
}
@Override
public MappedFieldType clone() {
return new DateFieldType(this);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) {
return false;
}
DateFieldType that = (DateFieldType) o;
return Objects.equals(dateTimeFormatter, that.dateTimeFormatter) && Objects.equals(resolution, that.resolution);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dateTimeFormatter, resolution);
}
@Override @Override
public String typeName() { public String typeName() {
return resolution.type(); return resolution.type();

View File

@ -38,7 +38,6 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* A mapper that indexes the field names of a document under <code>_field_names</code>. This mapper is typically useful in order * A mapper that indexes the field names of a document under <code>_field_names</code>. This mapper is typically useful in order
@ -135,28 +134,6 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper {
super(Defaults.NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(Defaults.NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected FieldNamesFieldType(FieldNamesFieldType ref) {
super(ref);
this.enabled = ref.enabled;
}
@Override
public FieldNamesFieldType clone() {
return new FieldNamesFieldType(this);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
FieldNamesFieldType that = (FieldNamesFieldType) o;
return enabled == that.enabled;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), enabled);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -172,20 +172,11 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<?
this(name, true, true, Collections.emptyMap()); this(name, true, true, Collections.emptyMap());
} }
GeoPointFieldType(GeoPointFieldType ref) {
super(ref);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
} }
@Override
public MappedFieldType clone() {
return new GeoPointFieldType(this);
}
@Override @Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues(); failIfNoDocValues();

View File

@ -91,15 +91,6 @@ public class GeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<Geomet
super(name, indexed, hasDocValues, meta); super(name, indexed, hasDocValues, meta);
} }
protected GeoShapeFieldType(GeoShapeFieldType ref) {
super(ref);
}
@Override
public GeoShapeFieldType clone() {
return new GeoShapeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -121,15 +121,6 @@ public class IdFieldMapper extends MetadataFieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
protected IdFieldType(IdFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new IdFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -87,15 +87,6 @@ public final class IgnoredFieldMapper extends MetadataFieldMapper {
super(NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected IgnoredFieldType(IgnoredFieldType ref) {
super(ref);
}
@Override
public IgnoredFieldType clone() {
return new IgnoredFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -87,15 +87,6 @@ public class IndexFieldMapper extends MetadataFieldMapper {
super(NAME, Collections.emptyMap()); super(NAME, Collections.emptyMap());
} }
protected IndexFieldType(IndexFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new IndexFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -148,15 +148,6 @@ public class IpFieldMapper extends FieldMapper {
this(name, true, true, Collections.emptyMap()); this(name, true, true, Collections.emptyMap());
} }
IpFieldType(IpFieldType other) {
super(other);
}
@Override
public MappedFieldType clone() {
return new IpFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -256,18 +256,6 @@ public final class KeywordFieldMapper extends FieldMapper {
super(name, true, true, new TextSearchInfo(Defaults.FIELD_TYPE, null, analyzer, analyzer), Collections.emptyMap()); super(name, true, true, new TextSearchInfo(Defaults.FIELD_TYPE, null, analyzer, analyzer), Collections.emptyMap());
} }
protected KeywordFieldType(KeywordFieldType ref) {
super(ref);
this.hasNorms = ref.hasNorms;
setEagerGlobalOrdinals(ref.eagerGlobalOrdinals());
setIndexAnalyzer(ref.indexAnalyzer());
}
@Override
public KeywordFieldType clone() {
return new KeywordFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -52,7 +52,6 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* FieldMapper for indexing {@link org.locationtech.spatial4j.shape.Shape}s. * FieldMapper for indexing {@link org.locationtech.spatial4j.shape.Shape}s.
@ -306,44 +305,6 @@ public class LegacyGeoShapeFieldMapper extends AbstractShapeGeometryFieldMapper<
this(name, true, true, Collections.emptyMap()); this(name, true, true, Collections.emptyMap());
} }
protected GeoShapeFieldType(GeoShapeFieldType ref) {
super(ref);
this.tree = ref.tree;
this.strategy = ref.strategy;
this.pointsOnly = ref.pointsOnly;
this.treeLevels = ref.treeLevels;
this.precisionInMeters = ref.precisionInMeters;
this.distanceErrorPct = ref.distanceErrorPct;
this.defaultDistanceErrorPct = ref.defaultDistanceErrorPct;
this.defaultPrefixTreeStrategy = ref.defaultPrefixTreeStrategy;
this.recursiveStrategy = ref.recursiveStrategy;
this.termStrategy = ref.termStrategy;
}
@Override
public GeoShapeFieldType clone() {
return new GeoShapeFieldType(this);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
GeoShapeFieldType that = (GeoShapeFieldType) o;
return treeLevels == that.treeLevels &&
precisionInMeters == that.precisionInMeters &&
defaultDistanceErrorPct == that.defaultDistanceErrorPct &&
Objects.equals(tree, that.tree) &&
Objects.equals(strategy, that.strategy) &&
pointsOnly == that.pointsOnly &&
Objects.equals(distanceErrorPct, that.distanceErrorPct);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), tree, strategy, pointsOnly, treeLevels, precisionInMeters, distanceErrorPct,
defaultDistanceErrorPct);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -68,17 +68,6 @@ public abstract class MappedFieldType {
private boolean eagerGlobalOrdinals; private boolean eagerGlobalOrdinals;
private Map<String, String> meta; private Map<String, String> meta;
protected MappedFieldType(MappedFieldType ref) {
this.name = ref.name();
this.boost = ref.boost();
this.isIndexed = ref.isIndexed;
this.docValues = ref.hasDocValues();
this.indexAnalyzer = ref.indexAnalyzer();
this.eagerGlobalOrdinals = ref.eagerGlobalOrdinals;
this.meta = ref.meta;
this.textSearchInfo = ref.textSearchInfo;
}
public MappedFieldType(String name, boolean isIndexed, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String, String> meta) { public MappedFieldType(String name, boolean isIndexed, boolean hasDocValues, TextSearchInfo textSearchInfo, Map<String, String> meta) {
setBoost(1.0f); setBoost(1.0f);
this.name = Objects.requireNonNull(name); this.name = Objects.requireNonNull(name);
@ -88,9 +77,6 @@ public abstract class MappedFieldType {
this.meta = meta; this.meta = meta;
} }
@Override
public abstract MappedFieldType clone();
/** /**
* Return a fielddata builder for this field * Return a fielddata builder for this field
* *
@ -104,32 +90,9 @@ public abstract class MappedFieldType {
throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]"); throw new IllegalArgumentException("Fielddata is not supported on field [" + name() + "] of type [" + typeName() + "]");
} }
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
MappedFieldType fieldType = (MappedFieldType) o;
return boost == fieldType.boost &&
docValues == fieldType.docValues &&
Objects.equals(name, fieldType.name) &&
Objects.equals(indexAnalyzer, fieldType.indexAnalyzer) &&
Objects.equals(eagerGlobalOrdinals, fieldType.eagerGlobalOrdinals) &&
Objects.equals(meta, fieldType.meta);
}
@Override
public int hashCode() {
return Objects.hash(name, boost, docValues, indexAnalyzer,
eagerGlobalOrdinals, meta);
}
// TODO: we need to override freeze() and add safety checks that all settings are actually set
/** Returns the name of this type, as would be specified in mapping properties */ /** Returns the name of this type, as would be specified in mapping properties */
public abstract String typeName(); public abstract String typeName();
/** Returns the field family type, as used in field capabilities */ /** Returns the field family type, as used in field capabilities */
public String familyTypeName() { public String familyTypeName() {
return typeName(); return typeName();

View File

@ -913,16 +913,6 @@ public class NumberFieldMapper extends FieldMapper {
this(name, type, true, true, Collections.emptyMap()); this(name, type, true, true, Collections.emptyMap());
} }
private NumberFieldType(NumberFieldType other) {
super(other);
this.type = other.type;
}
@Override
public MappedFieldType clone() {
return new NumberFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return type.name; return type.name;
@ -1001,20 +991,6 @@ public class NumberFieldMapper extends FieldMapper {
public Number parsePoint(byte[] value) { public Number parsePoint(byte[] value) {
return type.parsePoint(value); return type.parsePoint(value);
} }
@Override
public boolean equals(Object o) {
if (super.equals(o) == false) {
return false;
}
NumberFieldType that = (NumberFieldType) o;
return type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), type);
}
} }
private Explicit<Boolean> ignoreMalformed; private Explicit<Boolean> ignoreMalformed;

View File

@ -217,35 +217,8 @@ public class RangeFieldMapper extends FieldMapper {
this(name, true, true, formatter, Collections.emptyMap()); this(name, true, true, formatter, Collections.emptyMap());
} }
RangeFieldType(RangeFieldType other) {
super(other);
this.rangeType = other.rangeType;
this.dateTimeFormatter = other.dateTimeFormatter;
this.dateMathParser = other.dateMathParser;
}
public RangeType rangeType() { return rangeType; } public RangeType rangeType() { return rangeType; }
@Override
public RangeFieldType clone() {
return new RangeFieldType(this);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
RangeFieldType that = (RangeFieldType) o;
return Objects.equals(rangeType, that.rangeType) &&
(rangeType == RangeType.DATE) ?
Objects.equals(dateTimeFormatter, that.dateTimeFormatter)
: dateTimeFormatter == null && that.dateTimeFormatter == null;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), rangeType, dateTimeFormatter);
}
@Override @Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues(); failIfNoDocValues();

View File

@ -114,15 +114,6 @@ public class RoutingFieldMapper extends MetadataFieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
protected RoutingFieldType(RoutingFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new RoutingFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -125,15 +125,6 @@ public class SeqNoFieldMapper extends MetadataFieldMapper {
super(NAME, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(NAME, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected SeqNoFieldType(SeqNoFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new SeqNoFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -37,10 +37,6 @@ public abstract class SimpleMappedFieldType extends MappedFieldType {
super(name, isSearchable, hasDocValues, textSearchInfo, meta); super(name, isSearchable, hasDocValues, textSearchInfo, meta);
} }
protected SimpleMappedFieldType(MappedFieldType ref) {
super(ref);
}
@Override @Override
public final Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, public final Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
ShapeRelation relation, ZoneId timeZone, DateMathParser parser, QueryShardContext context) { ShapeRelation relation, ZoneId timeZone, DateMathParser parser, QueryShardContext context) {

View File

@ -152,15 +152,6 @@ public class SourceFieldMapper extends MetadataFieldMapper {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap()); super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
} }
protected SourceFieldType(SourceFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new SourceFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -55,10 +55,6 @@ public abstract class StringFieldType extends TermBasedFieldType {
super(name, isSearchable, hasDocValues, textSearchInfo, meta); super(name, isSearchable, hasDocValues, textSearchInfo, meta);
} }
protected StringFieldType(MappedFieldType ref) {
super(ref);
}
@Override @Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions,
boolean transpositions, QueryShardContext context) { boolean transpositions, QueryShardContext context) {

View File

@ -39,10 +39,6 @@ abstract class TermBasedFieldType extends SimpleMappedFieldType {
super(name, isSearchable, hasDocValues, textSearchInfo, meta); super(name, isSearchable, hasDocValues, textSearchInfo, meta);
} }
protected TermBasedFieldType(MappedFieldType ref) {
super(ref);
}
/** Returns the indexed value used to construct search "values". /** Returns the indexed value used to construct search "values".
* This method is used for the default implementations of most * This method is used for the default implementations of most
* query factory methods such as {@link #termQuery}. */ * query factory methods such as {@link #termQuery}. */

View File

@ -387,11 +387,6 @@ public class TextFieldMapper extends FieldMapper {
setIndexAnalyzer(new NamedAnalyzer(name, AnalyzerScope.INDEX, new PhraseWrappedAnalyzer(delegate))); setIndexAnalyzer(new NamedAnalyzer(name, AnalyzerScope.INDEX, new PhraseWrappedAnalyzer(delegate)));
} }
@Override
public MappedFieldType clone() {
return new PhraseFieldType(parent);
}
@Override @Override
public String typeName() { public String typeName() {
return "phrase"; return "phrase";
@ -418,6 +413,13 @@ public class TextFieldMapper extends FieldMapper {
this.hasPositions = hasPositions; this.hasPositions = hasPositions;
} }
static boolean canMerge(PrefixFieldType first, PrefixFieldType second) {
if (first == null) {
return second == null;
}
return second != null && first.minChars == second.minChars && first.maxChars == second.maxChars;
}
void setAnalyzer(NamedAnalyzer delegate) { void setAnalyzer(NamedAnalyzer delegate) {
setIndexAnalyzer(new NamedAnalyzer(delegate.name(), AnalyzerScope.INDEX, setIndexAnalyzer(new NamedAnalyzer(delegate.name(), AnalyzerScope.INDEX,
new PrefixWrappedAnalyzer(delegate.analyzer(), minChars, maxChars))); new PrefixWrappedAnalyzer(delegate.analyzer(), minChars, maxChars)));
@ -471,11 +473,6 @@ public class TextFieldMapper extends FieldMapper {
return Intervals.or(Intervals.fixField(name(), Intervals.wildcard(new BytesRef(wildcardTerm))), Intervals.term(term)); return Intervals.or(Intervals.fixField(name(), Intervals.wildcard(new BytesRef(wildcardTerm))), Intervals.term(term));
} }
@Override
public PrefixFieldType clone() {
return new PrefixFieldType(parentField, name(), minChars, maxChars, hasPositions);
}
@Override @Override
public String typeName() { public String typeName() {
return "prefix"; return "prefix";
@ -490,21 +487,6 @@ public class TextFieldMapper extends FieldMapper {
public Query existsQuery(QueryShardContext context) { public Query existsQuery(QueryShardContext context) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PrefixFieldType that = (PrefixFieldType) o;
return minChars == that.minChars &&
maxChars == that.maxChars;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), minChars, maxChars);
}
} }
private static final class PhraseFieldMapper extends FieldMapper { private static final class PhraseFieldMapper extends FieldMapper {
@ -592,44 +574,6 @@ public class TextFieldMapper extends FieldMapper {
this(name, Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER, Collections.emptyMap()); this(name, Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER, Collections.emptyMap());
} }
protected TextFieldType(TextFieldType ref) {
super(ref);
this.fielddata = ref.fielddata;
this.fielddataMinFrequency = ref.fielddataMinFrequency;
this.fielddataMaxFrequency = ref.fielddataMaxFrequency;
this.fielddataMinSegmentSize = ref.fielddataMinSegmentSize;
this.indexPhrases = ref.indexPhrases;
if (ref.prefixFieldType != null) {
this.prefixFieldType = ref.prefixFieldType.clone();
}
this.indexedFieldType = ref.indexedFieldType;
}
@Override
public TextFieldType clone() {
return new TextFieldType(this);
}
@Override
public boolean equals(Object o) {
if (super.equals(o) == false) {
return false;
}
TextFieldType that = (TextFieldType) o;
return fielddata == that.fielddata
&& indexPhrases == that.indexPhrases
&& Objects.equals(prefixFieldType, that.prefixFieldType)
&& fielddataMinFrequency == that.fielddataMinFrequency
&& fielddataMaxFrequency == that.fielddataMaxFrequency
&& fielddataMinSegmentSize == that.fielddataMinSegmentSize;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fielddata, indexPhrases, prefixFieldType,
fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize);
}
public boolean fielddata() { public boolean fielddata() {
return fielddata; return fielddata;
} }
@ -913,7 +857,7 @@ public class TextFieldMapper extends FieldMapper {
if (mw.fieldType().indexPhrases != this.fieldType().indexPhrases) { if (mw.fieldType().indexPhrases != this.fieldType().indexPhrases) {
conflicts.add("mapper [" + name() + "] has different [index_phrases] settings"); conflicts.add("mapper [" + name() + "] has different [index_phrases] settings");
} }
if (Objects.equals(mw.fieldType().prefixFieldType, this.fieldType().prefixFieldType) == false) { if (PrefixFieldType.canMerge(mw.fieldType().prefixFieldType, this.fieldType().prefixFieldType) == false) {
conflicts.add("mapper [" + name() + "] has different [index_prefixes] settings"); conflicts.add("mapper [" + name() + "] has different [index_prefixes] settings");
} }
if (this.prefixFieldMapper != null && mw.prefixFieldMapper != null) { if (this.prefixFieldMapper != null && mw.prefixFieldMapper != null) {

View File

@ -63,11 +63,6 @@ public class TimestampFieldMapper extends MetadataFieldMapper {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap()); super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
} }
@Override
public MappedFieldType clone() {
return new TimestampFieldType();
}
@Override @Override
public String typeName() { public String typeName() {
return NAME; return NAME;

View File

@ -104,15 +104,6 @@ public class TypeFieldMapper extends MetadataFieldMapper {
super(NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(NAME, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected TypeFieldType(TypeFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new TypeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -75,15 +75,6 @@ public class VersionFieldMapper extends MetadataFieldMapper {
super(NAME, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(NAME, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected VersionFieldType(VersionFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new VersionFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -1,29 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.mapper;
import java.util.Map;
public class BinaryFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new BinaryFieldMapper.BinaryFieldType(name, true, meta);
}
}

View File

@ -22,13 +22,8 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class BooleanFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class BooleanFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new BooleanFieldMapper.BooleanFieldType(name, true, true, meta);
}
public void testValueFormat() { public void testValueFormat() {
MappedFieldType ft = new BooleanFieldMapper.BooleanFieldType("field"); MappedFieldType ft = new BooleanFieldMapper.BooleanFieldType("field");

View File

@ -56,16 +56,8 @@ import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class DateFieldTypeTests extends FieldTypeTestCase<DateFieldType> { public class DateFieldTypeTests extends FieldTypeTestCase {
@Override
protected DateFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new DateFieldType(name, true, true, DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER,
Resolution.MILLISECONDS, meta);
}
private static final long nowInMillis = 0; private static final long nowInMillis = 0;

View File

@ -76,15 +76,6 @@ public class DocumentFieldMapperTests extends LuceneTestCase {
super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
FakeFieldType(FakeFieldType other) {
super(other);
}
@Override
public MappedFieldType clone() {
return new FakeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return "fake"; return "fake";

View File

@ -130,15 +130,6 @@ public class ExternalMapper extends FieldMapper {
super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected ExternalFieldType(ExternalFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new ExternalFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return "faketype"; return "faketype";

View File

@ -91,14 +91,6 @@ public class FakeStringFieldMapper extends FieldMapper {
setIndexAnalyzer(Lucene.STANDARD_ANALYZER); setIndexAnalyzer(Lucene.STANDARD_ANALYZER);
} }
protected FakeStringFieldType(FakeStringFieldType ref) {
super(ref);
}
public FakeStringFieldType clone() {
return new FakeStringFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -28,7 +28,6 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.EqualsHashCodeTestUtils;
import java.util.Collections; import java.util.Collections;
@ -61,14 +60,4 @@ public class FieldNamesFieldTypeTests extends ESTestCase {
IllegalStateException e = expectThrows(IllegalStateException.class, () -> fieldNamesFieldType.termQuery("field_name", null)); IllegalStateException e = expectThrows(IllegalStateException.class, () -> fieldNamesFieldType.termQuery("field_name", null));
assertEquals("Cannot run [exists] queries if the [_field_names] field is disabled", e.getMessage()); assertEquals("Cannot run [exists] queries if the [_field_names] field is disabled", e.getMessage());
} }
public void testHashcodeAndEquals() {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(new FieldNamesFieldMapper.FieldNamesFieldType(),
FieldNamesFieldMapper.FieldNamesFieldType::clone,
t -> {
FieldNamesFieldMapper.FieldNamesFieldType m = t.clone();
m.setEnabled(false);
return m;
});
}
} }

View File

@ -1,30 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.mapper;
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
import java.util.Map;
public class GeoPointFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new GeoPointFieldType(name, true, true, meta);
}
}

View File

@ -26,22 +26,8 @@ import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.test.EqualsHashCodeTestUtils;
import java.util.Map; public class IgnoredFieldTypeTests extends FieldTypeTestCase {
public class IgnoredFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
public void testEquals() {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(IgnoredFieldMapper.IgnoredFieldType.INSTANCE,
IgnoredFieldMapper.IgnoredFieldType::clone);
}
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return IgnoredFieldMapper.IgnoredFieldType.INSTANCE;
}
public void testPrefixQuery() { public void testPrefixQuery() {
MappedFieldType ft = IgnoredFieldMapper.IgnoredFieldType.INSTANCE; MappedFieldType ft = IgnoredFieldMapper.IgnoredFieldType.INSTANCE;

View File

@ -28,7 +28,6 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.EqualsHashCodeTestUtils;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -36,11 +35,6 @@ import static org.hamcrest.Matchers.containsString;
public class IndexFieldTypeTests extends ESTestCase { public class IndexFieldTypeTests extends ESTestCase {
public void testEqualsHashCode() {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(IndexFieldMapper.IndexFieldType.INSTANCE,
IndexFieldMapper.IndexFieldType::new);
}
public void testPrefixQuery() { public void testPrefixQuery() {
MappedFieldType ft = IndexFieldMapper.IndexFieldType.INSTANCE; MappedFieldType ft = IndexFieldMapper.IndexFieldType.INSTANCE;

View File

@ -29,13 +29,8 @@ import org.elasticsearch.common.network.InetAddresses;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class IpFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class IpFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new IpFieldMapper.IpFieldType(name, true, true, meta);
}
public void testValueFormat() throws Exception { public void testValueFormat() throws Exception {
MappedFieldType ft = new IpFieldMapper.IpFieldType("field"); MappedFieldType ft = new IpFieldMapper.IpFieldType("field");

View File

@ -48,14 +48,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class KeywordFieldTypeTests extends FieldTypeTestCase<KeywordFieldType> { public class KeywordFieldTypeTests extends FieldTypeTestCase {
@Override
protected KeywordFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new KeywordFieldMapper.KeywordFieldType(name, true, true, meta);
}
public void testIsFieldWithinQuery() throws IOException { public void testIsFieldWithinQuery() throws IOException {
KeywordFieldType ft = new KeywordFieldType("field"); KeywordFieldType ft = new KeywordFieldType("field");

View File

@ -21,13 +21,7 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.common.geo.SpatialStrategy; import org.elasticsearch.common.geo.SpatialStrategy;
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType; import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType;
import java.util.Map; public class LegacyGeoShapeFieldTypeTests extends FieldTypeTestCase {
public class LegacyGeoShapeFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new GeoShapeFieldType(name, true, true, meta);
}
/** /**
* Test for {@link LegacyGeoShapeFieldMapper.GeoShapeFieldType#setStrategy(SpatialStrategy)} that checks * Test for {@link LegacyGeoShapeFieldMapper.GeoShapeFieldType#setStrategy(SpatialStrategy)} that checks

View File

@ -61,14 +61,13 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
public class NumberFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class NumberFieldTypeTests extends FieldTypeTestCase {
NumberType type; NumberType type;
@ -77,11 +76,6 @@ public class NumberFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
type = RandomPicks.randomFrom(random(), NumberFieldMapper.NumberType.values()); type = RandomPicks.randomFrom(random(), NumberFieldMapper.NumberType.values());
} }
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new NumberFieldMapper.NumberFieldType(name, type, true, true, meta);
}
public void testEqualsWithDifferentNumberTypes() { public void testEqualsWithDifferentNumberTypes() {
NumberType type = randomFrom(NumberType.values()); NumberType type = randomFrom(NumberType.values());
NumberFieldType fieldType = new NumberFieldType("foo", type); NumberFieldType fieldType = new NumberFieldType("foo", type);
@ -94,7 +88,7 @@ public class NumberFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
} }
public void testIsFieldWithinQuery() throws IOException { public void testIsFieldWithinQuery() throws IOException {
MappedFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); MappedFieldType ft = new NumberFieldType("field", NumberType.INTEGER);
// current impl ignores args and should always return INTERSECTS // current impl ignores args and should always return INTERSECTS
assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(null, randomDouble(), randomDouble(), assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(null, randomDouble(), randomDouble(),
randomBoolean(), randomBoolean(), null, null, null)); randomBoolean(), randomBoolean(), null, null, null));

View File

@ -48,12 +48,11 @@ import org.junit.Before;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
public class RangeFieldTypeTests extends FieldTypeTestCase<RangeFieldType> { public class RangeFieldTypeTests extends FieldTypeTestCase {
RangeType type; RangeType type;
protected static String FIELDNAME = "field"; protected static String FIELDNAME = "field";
protected static int DISTANCE = 10; protected static int DISTANCE = 10;
@ -65,17 +64,16 @@ public class RangeFieldTypeTests extends FieldTypeTestCase<RangeFieldType> {
nowInMillis = randomNonNegativeLong(); nowInMillis = randomNonNegativeLong();
} }
@Override protected RangeFieldType createDefaultFieldType(String name) {
protected RangeFieldType createDefaultFieldType(String name, Map<String, String> meta) {
if (type == RangeType.DATE) { if (type == RangeType.DATE) {
return new RangeFieldType(name, true, true, RangeFieldMapper.Defaults.DATE_FORMATTER, meta); return new RangeFieldType(name, true, true, RangeFieldMapper.Defaults.DATE_FORMATTER, Collections.emptyMap());
} }
return new RangeFieldType(name, type, true, true, meta); return new RangeFieldType(name, type, true, true, Collections.emptyMap());
} }
public void testRangeQuery() throws Exception { public void testRangeQuery() throws Exception {
QueryShardContext context = createContext(); QueryShardContext context = createContext();
RangeFieldType ft = createDefaultFieldType(FIELDNAME, Collections.emptyMap()); RangeFieldType ft = createDefaultFieldType(FIELDNAME);
ShapeRelation relation = randomFrom(ShapeRelation.values()); ShapeRelation relation = randomFrom(ShapeRelation.values());
boolean includeLower = randomBoolean(); boolean includeLower = randomBoolean();
@ -97,7 +95,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase<RangeFieldType> {
public void testRangeQueryIntersectsAdjacentValues() throws Exception { public void testRangeQueryIntersectsAdjacentValues() throws Exception {
QueryShardContext context = createContext(); QueryShardContext context = createContext();
ShapeRelation relation = randomFrom(ShapeRelation.values()); ShapeRelation relation = randomFrom(ShapeRelation.values());
RangeFieldType ft = createDefaultFieldType(FIELDNAME, Collections.emptyMap()); RangeFieldType ft = createDefaultFieldType(FIELDNAME);
Object from = null; Object from = null;
Object to = null; Object to = null;
@ -154,7 +152,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase<RangeFieldType> {
*/ */
public void testFromLargerToErrors() throws Exception { public void testFromLargerToErrors() throws Exception {
QueryShardContext context = createContext(); QueryShardContext context = createContext();
RangeFieldType ft = createDefaultFieldType(FIELDNAME, Collections.emptyMap()); RangeFieldType ft = createDefaultFieldType(FIELDNAME);
final Object from; final Object from;
final Object to; final Object to;
@ -474,7 +472,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase<RangeFieldType> {
public void testTermQuery() throws Exception { public void testTermQuery() throws Exception {
// See https://github.com/elastic/elasticsearch/issues/25950 // See https://github.com/elastic/elasticsearch/issues/25950
QueryShardContext context = createContext(); QueryShardContext context = createContext();
RangeFieldType ft = createDefaultFieldType(FIELDNAME, Collections.emptyMap()); RangeFieldType ft = createDefaultFieldType(FIELDNAME);
Object value = nextFrom(); Object value = nextFrom();
ShapeRelation relation = ShapeRelation.INTERSECTS; ShapeRelation relation = ShapeRelation.INTERSECTS;

View File

@ -25,22 +25,8 @@ import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.test.EqualsHashCodeTestUtils;
import java.util.Map; public class RoutingFieldTypeTests extends FieldTypeTestCase {
public class RoutingFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return RoutingFieldMapper.RoutingFieldType.INSTANCE;
}
@Override
public void testEquals() {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(RoutingFieldMapper.RoutingFieldType.INSTANCE,
RoutingFieldMapper.RoutingFieldType::new);
}
public void testPrefixQuery() { public void testPrefixQuery() {
MappedFieldType ft = RoutingFieldMapper.RoutingFieldType.INSTANCE; MappedFieldType ft = RoutingFieldMapper.RoutingFieldType.INSTANCE;

View File

@ -38,47 +38,16 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType; import org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType;
import org.junit.Before;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE; import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class TextFieldTypeTests extends FieldTypeTestCase<TextFieldType> { public class TextFieldTypeTests extends FieldTypeTestCase {
@Before
public void addModifiers() {
addModifier(t -> {
TextFieldType copy = t.clone();
copy.setFielddata(t.fielddata() == false);
return copy;
});
addModifier(t -> {
TextFieldType copy = t.clone();
copy.setFielddataMaxFrequency(t.fielddataMaxFrequency() + 1);
return copy;
});
addModifier(t -> {
TextFieldType copy = t.clone();
copy.setFielddataMinFrequency(t.fielddataMinFrequency() + 1);
return copy;
});
addModifier(t -> {
TextFieldType copy = t.clone();
copy.setFielddataMinSegmentSize(t.fielddataMinSegmentSize() + 1);
return copy;
});
}
@Override
protected TextFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new TextFieldType(name, true, meta);
}
public void testTermQuery() { public void testTermQuery() {
MappedFieldType ft = new TextFieldType("field"); MappedFieldType ft = new TextFieldType("field");

View File

@ -198,11 +198,6 @@ public class CollapseBuilderTests extends AbstractSerializingTestCase<CollapseBu
{ {
MappedFieldType fieldType = new MappedFieldType("field", true, true, TextSearchInfo.NONE, Collections.emptyMap()) { MappedFieldType fieldType = new MappedFieldType("field", true, true, TextSearchInfo.NONE, Collections.emptyMap()) {
@Override
public MappedFieldType clone() {
return null;
}
@Override @Override
public String typeName() { public String typeName() {
return null; return null;

View File

@ -120,10 +120,6 @@ public class SliceBuilderTests extends ESTestCase {
private QueryShardContext createShardContext(Version indexVersionCreated, IndexReader reader, private QueryShardContext createShardContext(Version indexVersionCreated, IndexReader reader,
String fieldName, DocValuesType dvType, int numShards, int shardId) { String fieldName, DocValuesType dvType, int numShards, int shardId) {
MappedFieldType fieldType = new MappedFieldType(fieldName, true, dvType != null, TextSearchInfo.NONE, Collections.emptyMap()) { MappedFieldType fieldType = new MappedFieldType(fieldName, true, dvType != null, TextSearchInfo.NONE, Collections.emptyMap()) {
@Override
public MappedFieldType clone() {
return null;
}
@Override @Override
public String typeName() { public String typeName() {

View File

@ -20,51 +20,16 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.EqualsHashCodeTestUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** Base test case for subclasses of MappedFieldType */ /** Base test case for subclasses of MappedFieldType */
public abstract class FieldTypeTestCase<T extends MappedFieldType> extends ESTestCase { public abstract class FieldTypeTestCase extends ESTestCase {
public static final QueryShardContext MOCK_QSC = createMockQueryShardContext(true); public static final QueryShardContext MOCK_QSC = createMockQueryShardContext(true);
public static final QueryShardContext MOCK_QSC_DISALLOW_EXPENSIVE = createMockQueryShardContext(false); public static final QueryShardContext MOCK_QSC_DISALLOW_EXPENSIVE = createMockQueryShardContext(false);
/** Create a default constructed fieldtype */
protected abstract T createDefaultFieldType(String name, Map<String, String> meta);
@SuppressWarnings("unchecked")
private final List<EqualsHashCodeTestUtils.MutateFunction<T>> modifiers = new ArrayList<>(Arrays.asList(
t -> createDefaultFieldType(t.name() + "-mutated", t.meta()),
t -> {
MappedFieldType copy = t.clone();
copy.setBoost(t.boost() + 1);
return (T) copy;
},
t -> {
MappedFieldType copy = t.clone();
copy.setEagerGlobalOrdinals(t.eagerGlobalOrdinals() == false);
return (T) copy;
},
t -> {
Map<String, String> meta = new HashMap<>(t.meta());
meta.put("bogus", "bogus");
return createDefaultFieldType(t.name(), meta);
}
));
protected void addModifier(EqualsHashCodeTestUtils.MutateFunction<T> modifier) {
modifiers.add(modifier);
}
protected QueryShardContext randomMockShardContext() { protected QueryShardContext randomMockShardContext() {
return randomFrom(MOCK_QSC, MOCK_QSC_DISALLOW_EXPENSIVE); return randomFrom(MOCK_QSC, MOCK_QSC_DISALLOW_EXPENSIVE);
} }
@ -75,17 +40,4 @@ public abstract class FieldTypeTestCase<T extends MappedFieldType> extends ESTes
return queryShardContext; return queryShardContext;
} }
public void testClone() {
MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap());
EqualsHashCodeTestUtils.checkEqualsAndHashCode(fieldType, MappedFieldType::clone);
}
@SuppressWarnings("unchecked")
public void testEquals() {
for (EqualsHashCodeTestUtils.MutateFunction<T> modifier : modifiers) {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createDefaultFieldType("foo", Collections.emptyMap()),
t -> (T) t.clone(), modifier);
}
}
} }

View File

@ -52,15 +52,6 @@ public class MockFieldMapper extends FieldMapper {
super(name, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); super(name, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
} }
protected FakeFieldType(FakeFieldType ref) {
super(ref);
}
@Override
public MappedFieldType clone() {
return new FakeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return "faketype"; return "faketype";

View File

@ -170,20 +170,11 @@ public class HistogramFieldMapper extends FieldMapper {
super(name, false, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); super(name, false, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
} }
HistogramFieldType(HistogramFieldType ref) {
super(ref);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
} }
@Override
public MappedFieldType clone() {
return new HistogramFieldType(this);
}
@Override @Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues(); failIfNoDocValues();

View File

@ -1,21 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.analytics.mapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import java.util.Map;
public class HistogramFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new HistogramFieldMapper.HistogramFieldType(name, true, meta);
}
}

View File

@ -122,29 +122,6 @@ public class ConstantKeywordFieldMapper extends FieldMapper {
this(name, value, Collections.emptyMap()); this(name, value, Collections.emptyMap());
} }
protected ConstantKeywordFieldType(ConstantKeywordFieldType ref) {
super(ref);
this.value = ref.value;
}
public ConstantKeywordFieldType clone() {
return new ConstantKeywordFieldType(this);
}
@Override
public boolean equals(Object o) {
if (super.equals(o) == false) {
return false;
}
ConstantKeywordFieldType other = (ConstantKeywordFieldType) o;
return Objects.equals(value, other.value);
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(value);
}
/** Return the value that this field wraps. This may be {@code null} if the field is not configured yet. */ /** Return the value that this field wraps. This may be {@code null} if the field is not configured yet. */
public String value() { public String value() {
return value; return value;

View File

@ -11,19 +11,12 @@ import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.util.automaton.RegExp; import org.apache.lucene.util.automaton.RegExp;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper.ConstantKeywordFieldType; import org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper.ConstantKeywordFieldType;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class ConstantKeywordFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class ConstantKeywordFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new ConstantKeywordFieldType(name, "foo", meta);
}
public void testTermQuery() { public void testTermQuery() {
ConstantKeywordFieldType ft = new ConstantKeywordFieldType("f", "foo"); ConstantKeywordFieldType ft = new ConstantKeywordFieldType("f", "foo");

View File

@ -237,34 +237,10 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
this.splitQueriesOnWhitespace = splitQueriesOnWhitespace; this.splitQueriesOnWhitespace = splitQueriesOnWhitespace;
} }
public KeyedFlatObjectFieldType clone() {
return new KeyedFlatObjectFieldType(this);
}
private KeyedFlatObjectFieldType(KeyedFlatObjectFieldType ref) {
super(ref);
this.key = ref.key;
this.splitQueriesOnWhitespace = ref.splitQueriesOnWhitespace;
}
private KeyedFlatObjectFieldType(String name, String key, RootFlatObjectFieldType ref) { private KeyedFlatObjectFieldType(String name, String key, RootFlatObjectFieldType ref) {
this(name, ref.isSearchable(), ref.hasDocValues(), key, ref.splitQueriesOnWhitespace, ref.meta()); this(name, ref.isSearchable(), ref.hasDocValues(), key, ref.splitQueriesOnWhitespace, ref.meta());
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
KeyedFlatObjectFieldType that = (KeyedFlatObjectFieldType) o;
return splitQueriesOnWhitespace == that.splitQueriesOnWhitespace;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), splitQueriesOnWhitespace);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
@ -483,29 +459,6 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
} }
private RootFlatObjectFieldType(RootFlatObjectFieldType ref) {
super(ref);
this.splitQueriesOnWhitespace = ref.splitQueriesOnWhitespace;
}
public RootFlatObjectFieldType clone() {
return new RootFlatObjectFieldType(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
RootFlatObjectFieldType that = (RootFlatObjectFieldType) o;
return splitQueriesOnWhitespace == that.splitQueriesOnWhitespace;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), splitQueriesOnWhitespace);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -18,31 +18,19 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper.KeyedFlatObjectFieldType; import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper.KeyedFlatObjectFieldType;
import org.junit.Before;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatObjectFieldType> { public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase {
@Before protected KeyedFlatObjectFieldType createFieldType() {
public void addModifiers() { return new KeyedFlatObjectFieldType("field", true, true, "key", false, Collections.emptyMap());
addModifier(t -> {
KeyedFlatObjectFieldType copy = t.clone();
copy.setSplitQueriesOnWhitespace(t.splitQueriesOnWhitespace() == false);
return copy;
});
}
@Override
protected KeyedFlatObjectFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new KeyedFlatObjectFieldType(name, true, true, "key", false, meta);
} }
public void testIndexedValueForSearch() { public void testIndexedValueForSearch() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
BytesRef keywordValue = ft.indexedValueForSearch("value"); BytesRef keywordValue = ft.indexedValueForSearch("value");
assertEquals(new BytesRef("key\0value"), keywordValue); assertEquals(new BytesRef("key\0value"), keywordValue);
@ -55,7 +43,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testTermQuery() { public void testTermQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
Query expected = new TermQuery(new Term("field", "key\0value")); Query expected = new TermQuery(new Term("field", "key\0value"));
assertEquals(expected, ft.termQuery("value", null)); assertEquals(expected, ft.termQuery("value", null));
@ -68,7 +56,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testTermsQuery() { public void testTermsQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
Query expected = new TermInSetQuery("field", Query expected = new TermInSetQuery("field",
new BytesRef("key\0value1"), new BytesRef("key\0value1"),
@ -83,14 +71,14 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testExistsQuery() { public void testExistsQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
Query expected = new PrefixQuery(new Term("field", "key\0")); Query expected = new PrefixQuery(new Term("field", "key\0"));
assertEquals(expected, ft.existsQuery(null)); assertEquals(expected, ft.existsQuery(null));
} }
public void testPrefixQuery() { public void testPrefixQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
Query expected = new PrefixQuery(new Term("field", "key\0val")); Query expected = new PrefixQuery(new Term("field", "key\0val"));
assertEquals(expected, ft.prefixQuery("val", MultiTermQuery.CONSTANT_SCORE_REWRITE, MOCK_QSC)); assertEquals(expected, ft.prefixQuery("val", MultiTermQuery.CONSTANT_SCORE_REWRITE, MOCK_QSC));
@ -102,7 +90,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testFuzzyQuery() { public void testFuzzyQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.fuzzyQuery("value", Fuzziness.fromEdits(2), 1, 50, true, randomMockShardContext())); () -> ft.fuzzyQuery("value", Fuzziness.fromEdits(2), 1, 50, true, randomMockShardContext()));
@ -110,7 +98,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testRangeQuery() { public void testRangeQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
TermRangeQuery expected = new TermRangeQuery("field", TermRangeQuery expected = new TermRangeQuery("field",
new BytesRef("key\0lower"), new BytesRef("key\0lower"),
@ -139,7 +127,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testRegexpQuery() { public void testRegexpQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.regexpQuery("valu*", 0, 10, null, randomMockShardContext())); () -> ft.regexpQuery("valu*", 0, 10, null, randomMockShardContext()));
@ -147,7 +135,7 @@ public class KeyedFlatObjectFieldTypeTests extends FieldTypeTestCase<KeyedFlatOb
} }
public void testWildcardQuery() { public void testWildcardQuery() {
KeyedFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); KeyedFlatObjectFieldType ft = createFieldType();
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.wildcardQuery("valu*", null, randomMockShardContext())); () -> ft.wildcardQuery("valu*", null, randomMockShardContext()));

View File

@ -20,29 +20,17 @@ import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper.RootFlatObjectFieldType; import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper.RootFlatObjectFieldType;
import org.junit.Before;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObjectFieldType> { public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase {
@Before protected RootFlatObjectFieldType createDefaultFieldType() {
public void addModifiers() { return new RootFlatObjectFieldType("field", true, true, Collections.emptyMap(), false);
addModifier(t -> {
RootFlatObjectFieldType copy = t.clone();
copy.setSplitQueriesOnWhitespace(t.splitQueriesOnWhitespace() == false);
return copy;
});
}
@Override
protected RootFlatObjectFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new RootFlatObjectFieldType(name, true, true, meta, false);
} }
public void testValueForDisplay() { public void testValueForDisplay() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
String fieldValue = "{ \"key\": \"value\" }"; String fieldValue = "{ \"key\": \"value\" }";
BytesRef storedValue = new BytesRef(fieldValue); BytesRef storedValue = new BytesRef(fieldValue);
@ -50,7 +38,7 @@ public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObje
} }
public void testTermQuery() { public void testTermQuery() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
Query expected = new TermQuery(new Term("field", "value")); Query expected = new TermQuery(new Term("field", "value"));
assertEquals(expected, ft.termQuery("value", null)); assertEquals(expected, ft.termQuery("value", null));
@ -73,7 +61,7 @@ public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObje
} }
public void testFuzzyQuery() { public void testFuzzyQuery() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
Query expected = new FuzzyQuery(new Term("field", "value"), 2, 1, 50, true); Query expected = new FuzzyQuery(new Term("field", "value"), 2, 1, 50, true);
Query actual = ft.fuzzyQuery("value", Fuzziness.fromEdits(2), 1, 50, true, MOCK_QSC); Query actual = ft.fuzzyQuery("value", Fuzziness.fromEdits(2), 1, 50, true, MOCK_QSC);
@ -87,7 +75,7 @@ public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObje
} }
public void testRangeQuery() { public void testRangeQuery() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
TermRangeQuery expected = new TermRangeQuery("field", TermRangeQuery expected = new TermRangeQuery("field",
new BytesRef("lower"), new BytesRef("lower"),
@ -106,7 +94,7 @@ public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObje
} }
public void testRegexpQuery() { public void testRegexpQuery() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
Query expected = new RegexpQuery(new Term("field", "val.*")); Query expected = new RegexpQuery(new Term("field", "val.*"));
Query actual = ft.regexpQuery("val.*", 0, 10, null, MOCK_QSC); Query actual = ft.regexpQuery("val.*", 0, 10, null, MOCK_QSC);
@ -119,7 +107,7 @@ public class RootFlatObjectFieldTypeTests extends FieldTypeTestCase<RootFlatObje
} }
public void testWildcardQuery() { public void testWildcardQuery() {
RootFlatObjectFieldType ft = createDefaultFieldType("field", Collections.emptyMap()); RootFlatObjectFieldType ft = createDefaultFieldType();
Query expected = new WildcardQuery(new Term("field", new BytesRef("valu*"))); Query expected = new WildcardQuery(new Term("field", new BytesRef("valu*")));
assertEquals(expected, ft.wildcardQuery("valu*", null, MOCK_QSC)); assertEquals(expected, ft.wildcardQuery("valu*", null, MOCK_QSC));

View File

@ -130,19 +130,10 @@ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper {
super(name, indexed, hasDocValues, meta); super(name, indexed, hasDocValues, meta);
} }
protected GeoShapeWithDocValuesFieldType(GeoShapeWithDocValuesFieldType ref) {
super(ref);
}
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues(); failIfNoDocValues();
return new AbstractLatLonShapeIndexFieldData.Builder(GeoShapeValuesSourceType.instance()); return new AbstractLatLonShapeIndexFieldData.Builder(GeoShapeValuesSourceType.instance());
} }
@Override
public GeoShapeWithDocValuesFieldType clone() {
return new GeoShapeWithDocValuesFieldType(this);
}
} }
public static final class TypeParser extends AbstractShapeGeometryFieldMapper.TypeParser { public static final class TypeParser extends AbstractShapeGeometryFieldMapper.TypeParser {

View File

@ -131,19 +131,10 @@ public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? ex
super(name, indexed, hasDocValues, meta); super(name, indexed, hasDocValues, meta);
} }
PointFieldType(PointFieldType ref) {
super(ref);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
} }
@Override
public MappedFieldType clone() {
return new PointFieldType(this);
}
} }
protected static class ParsedCartesianPoint extends CartesianPoint implements ParsedPoint { protected static class ParsedCartesianPoint extends CartesianPoint implements ParsedPoint {

View File

@ -81,15 +81,6 @@ public class ShapeFieldMapper extends AbstractShapeGeometryFieldMapper<Geometry,
super(name, indexed, hasDocValues, meta); super(name, indexed, hasDocValues, meta);
} }
public ShapeFieldType(ShapeFieldType ref) {
super(ref);
}
@Override
public ShapeFieldType clone() {
return new ShapeFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -1,35 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.spatial.index.mapper;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeWithDocValuesFieldMapper.GeoShapeWithDocValuesFieldType;
import org.junit.Before;
import java.util.Map;
public class GeoShapeWithDocValuesFieldTypeTests extends FieldTypeTestCase<GeoShapeWithDocValuesFieldType> {
@Before
public void addModifiers() {
addModifier(t -> {
GeoShapeWithDocValuesFieldType copy = t.clone();
if (copy.orientation() == ShapeBuilder.Orientation.RIGHT) {
copy.setOrientation(ShapeBuilder.Orientation.LEFT);
} else {
copy.setOrientation(ShapeBuilder.Orientation.RIGHT);
}
return copy;
});
}
@Override
protected GeoShapeWithDocValuesFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new GeoShapeWithDocValuesFieldType(name, true, true, meta);
}
}

View File

@ -1,18 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.spatial.index.mapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import java.util.Map;
public class PointFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new PointFieldMapper.PointFieldType(name, true, true, meta);
}
}

View File

@ -104,15 +104,6 @@ public class DenseVectorFieldMapper extends FieldMapper {
this.dims = dims; this.dims = dims;
} }
protected DenseVectorFieldType(DenseVectorFieldType ref) {
super(ref);
this.dims = ref.dims;
}
public DenseVectorFieldType clone() {
return new DenseVectorFieldType(this);
}
int dims() { int dims() {
return dims; return dims;
} }

View File

@ -90,14 +90,6 @@ public class SparseVectorFieldMapper extends FieldMapper {
super(name, false, false, TextSearchInfo.NONE, meta); super(name, false, false, TextSearchInfo.NONE, meta);
} }
protected SparseVectorFieldType(SparseVectorFieldType ref) {
super(ref);
}
public SparseVectorFieldType clone() {
return new SparseVectorFieldType(this);
}
@Override @Override
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -1,21 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.vectors.mapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import java.util.Map;
public class DenseVectorFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new DenseVectorFieldMapper.DenseVectorFieldType(name, 4, meta);
}
}

View File

@ -10,12 +10,12 @@ package org.elasticsearch.xpack.vectors.mapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType;
import java.util.Map; import java.util.Collections;
public class SparseVectorFieldTypeTests extends FieldTypeTestCase<MappedFieldType> { public class SparseVectorFieldTypeTests extends FieldTypeTestCase {
@Override public void testDocValuesDisabled() {
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) { MappedFieldType fieldType = new SparseVectorFieldMapper.SparseVectorFieldType("field", Collections.emptyMap());
return new SparseVectorFieldMapper.SparseVectorFieldType(name, meta); expectThrows(IllegalArgumentException.class, () -> fieldType.fielddataBuilder("index"));
} }
} }

View File

@ -217,16 +217,6 @@ public class WildcardFieldMapper extends FieldMapper {
setIndexAnalyzer(WILDCARD_ANALYZER); setIndexAnalyzer(WILDCARD_ANALYZER);
} }
protected WildcardFieldType(WildcardFieldType ref) {
super(ref);
}
public WildcardFieldType clone() {
WildcardFieldType result = new WildcardFieldType(this);
return result;
}
@Override @Override
public Query wildcardQuery(String wildcardPattern, RewriteMethod method, QueryShardContext context) { public Query wildcardQuery(String wildcardPattern, RewriteMethod method, QueryShardContext context) {
@ -849,12 +839,12 @@ public class WildcardFieldMapper extends FieldMapper {
public String typeName() { public String typeName() {
return CONTENT_TYPE; return CONTENT_TYPE;
} }
@Override @Override
public String familyTypeName() { public String familyTypeName() {
return KeywordFieldMapper.CONTENT_TYPE; return KeywordFieldMapper.CONTENT_TYPE;
} }
@Override @Override
public Query existsQuery(QueryShardContext context) { public Query existsQuery(QueryShardContext context) {

View File

@ -1,21 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.wildcard.mapper;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import java.util.Map;
public class WildcardFieldTypeTests extends FieldTypeTestCase<MappedFieldType> {
@Override
protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) {
return new WildcardFieldMapper.WildcardFieldType(name, WildcardFieldMapper.Defaults.FIELD_TYPE, meta);
}
}