Apache Lucene open-source search software
LUCENE-6426: Fix FieldType's copy constructor to also copy over the numeric precision step.
Adrien Grand7a4bd835582d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex d114c483bdd..a0d3d69f2a4 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -98,6 +98,9 @@ Bug Fixesalways consistently wrap Path, fix buggy behavior for globs, etc.(Ryan Ernst, Simon Willnauer, Robert Muir)+* LUCENE-6426: Fix FieldType's copy constructor to also copy over the numeric+ precision step. (Adrien Grand)+API Changes* LUCENE-6377: SearcherFactory#newSearcher now accepts the previous readerdiff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.javaindex b2b968e87c4..6ca3a02214b 100644--- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java+++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java@@ -68,8 +68,9 @@ public class FieldType implements IndexableFieldType {this.storeTermVectorPayloads = ref.storeTermVectorPayloads();this.omitNorms = ref.omitNorms();this.indexOptions = ref.indexOptions();- this.docValuesType = ref.docValuesType();this.numericType = ref.numericType();+ this.numericPrecisionStep = ref.numericPrecisionStep();+ this.docValuesType = ref.docValuesType();// Do not copy frozen!}diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.javaindex b26a10d4620..c9f242aabb2 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java@@ -17,11 +17,16 @@ package org.apache.lucene.document;* limitations under the License.*/+import java.lang.reflect.Method;+import java.lang.reflect.Modifier;+import org.apache.lucene.document.FieldType.NumericType;import org.apache.lucene.index.DocValuesType;import org.apache.lucene.index.IndexOptions;import org.apache.lucene.util.LuceneTestCase;+import com.carrotsearch.randomizedtesting.generators.RandomPicks;+/** simple testcases for concrete impl of IndexableFieldType */public class TestFieldType extends LuceneTestCase {@@ -65,6 +70,40 @@ public class TestFieldType extends LuceneTestCase {FieldType ft10 = new FieldType();ft10.setStoreTermVectors(true);assertFalse(ft10.equals(ft));+ }++ private static Object randomValue(Class<?> clazz) {+ if (clazz.isEnum()) {+ return RandomPicks.randomFrom(random(), clazz.getEnumConstants());+ } else if (clazz == boolean.class) {+ return random().nextBoolean();+ } else if (clazz == int.class) {+ return 1 + random().nextInt(100);+ }+ throw new AssertionError("Don't know how to generate a " + clazz);+ }++ private static FieldType randomFieldType() throws Exception {+ FieldType ft = new FieldType();+ for (Method method : FieldType.class.getMethods()) {+ if ((method.getModifiers() & Modifier.PUBLIC) != 0 && method.getName().startsWith("set")) {+ final Class<?>[] parameterTypes = method.getParameterTypes();+ final Object[] args = new Object[parameterTypes.length];+ for (int i = 0; i < args.length; ++i) {+ args[i] = randomValue(parameterTypes[i]);+ }+ method.invoke(ft, args);+ }+ }+ return ft;+ }+ public void testCopyConstructor() throws Exception {+ final int iters = 10;+ for (int iter = 0; iter < iters; ++iter) {+ FieldType ft = randomFieldType();+ FieldType ft2 = new FieldType(ft);+ assertEquals(ft, ft2);+ }}}