In NumberFieldType equals and hashCode, make sure that NumberType is taken into account. (#31514)
This commit is contained in:
parent
99f503e3be
commit
3b7225e9d1
|
@ -846,7 +846,7 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
|
||||
public static final class NumberFieldType extends SimpleMappedFieldType {
|
||||
|
||||
NumberType type;
|
||||
private final NumberType type;
|
||||
|
||||
public NumberFieldType(NumberType type) {
|
||||
super();
|
||||
|
@ -856,7 +856,7 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
setOmitNorms(true);
|
||||
}
|
||||
|
||||
NumberFieldType(NumberFieldType other) {
|
||||
private NumberFieldType(NumberFieldType other) {
|
||||
super(other);
|
||||
this.type = other.type;
|
||||
}
|
||||
|
@ -936,6 +936,20 @@ public class NumberFieldMapper extends FieldMapper {
|
|||
return new DocValueFormat.Decimal(format);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.FloatPoint;
|
||||
import org.apache.lucene.document.HalfFloatPoint;
|
||||
|
@ -37,10 +36,11 @@ import org.apache.lucene.search.MatchNoDocsQuery;
|
|||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.core.internal.io.IOUtils;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.core.internal.io.IOUtils;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType.Relation;
|
||||
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
|
||||
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -68,6 +68,17 @@ public class NumberFieldTypeTests extends FieldTypeTestCase {
|
|||
return new NumberFieldMapper.NumberFieldType(type);
|
||||
}
|
||||
|
||||
public void testEqualsWithDifferentNumberTypes() {
|
||||
NumberType type = randomFrom(NumberType.values());
|
||||
NumberFieldType fieldType = new NumberFieldType(type);
|
||||
|
||||
NumberType otherType = randomValueOtherThan(type,
|
||||
() -> randomFrom(NumberType.values()));
|
||||
NumberFieldType otherFieldType = new NumberFieldType(otherType);
|
||||
|
||||
assertNotEquals(fieldType, otherFieldType);
|
||||
}
|
||||
|
||||
public void testIsFieldWithinQuery() throws IOException {
|
||||
MappedFieldType ft = createDefaultFieldType();
|
||||
// current impl ignores args and should always return INTERSECTS
|
||||
|
|
Loading…
Reference in New Issue