lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1673790 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/document/FieldType.java core/src/test/org/apache/lucene/document/TestFieldType.java
Date Wed, 15 Apr 2015 14:42:13 GMT
Author: jpountz
Date: Wed Apr 15 14:42:13 2015
New Revision: 1673790

URL: http://svn.apache.org/r1673790
Log:
LUCENE-6426: Fix FieldType's copy constructor to also copy over the numeric precision step.

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/FieldType.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1673790&r1=1673789&r2=1673790&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Wed Apr 15 14:42:13 2015
@@ -98,6 +98,9 @@ Bug Fixes
   always 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 reader

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/FieldType.java?rev=1673790&r1=1673789&r2=1673790&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/FieldType.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/FieldType.java Wed Apr
15 14:42:13 2015
@@ -68,8 +68,9 @@ public class FieldType implements Indexa
     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!
   }
   

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java?rev=1673790&r1=1673789&r2=1673790&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java Wed
Apr 15 14:42:13 2015
@@ -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 Lucen
     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);
+    }
   }
 }



Mime
View raw message