You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ju...@apache.org on 2021/02/10 18:02:11 UTC

[lucene-solr] branch branch_8x updated: LUCENE-9756: Extend FieldInfosFormat tests to cover points and vectors (#2338)

This is an automated email from the ASF dual-hosted git repository.

julietibs pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new b5f7df3  LUCENE-9756: Extend FieldInfosFormat tests to cover points and vectors (#2338)
b5f7df3 is described below

commit b5f7df32c3ccbf240410b31c2d2ea6c761f7aaf7
Author: Julie Tibshirani <ju...@elastic.co>
AuthorDate: Wed Feb 10 08:57:26 2021 -0800

    LUCENE-9756: Extend FieldInfosFormat tests to cover points and vectors (#2338)
    
    This commit adds coverage to `BaseFieldInfoFormatTestCase ` for points,
    vectors, and the soft deletes field.
    
    NOTE: this backport omits vectors changes, since vectors were added in 9.0.
---
 .../lucene/index/BaseFieldInfoFormatTestCase.java  | 52 +++++++++++++---------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java
index ed21126..5fbb4cb 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java
@@ -66,6 +66,8 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
     assertFalse(infos2.fieldInfo("field").omitsNorms());
     assertFalse(infos2.fieldInfo("field").hasPayloads());
     assertFalse(infos2.fieldInfo("field").hasVectors());
+    assertEquals(0, infos2.fieldInfo("field").getPointDimensionCount());
+    assertFalse(infos2.fieldInfo("field").isSoftDeletesField());
     dir.close();
   }
   
@@ -242,7 +244,12 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
     for (int i = 0; i < numFields; i++) {
       fieldNames.add(TestUtil.randomUnicodeString(random()));
     }
-    FieldInfos.Builder builder = new FieldInfos.Builder(new FieldInfos.FieldNumbers(null));
+
+    String softDeletesField =
+        random().nextBoolean() ? TestUtil.randomUnicodeString(random()) : null;
+    FieldInfos.Builder builder =
+        new FieldInfos.Builder(new FieldInfos.FieldNumbers(softDeletesField));
+
     for (String field : fieldNames) {
       IndexableFieldType fieldType = randomFieldType(random());
       FieldInfo fi = builder.getOrAdd(field);
@@ -259,6 +266,14 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
           fi.setStorePayloads();
         }
       }
+
+      if (fieldType.pointDimensionCount() > 0) {
+        fi.setPointDimensions(
+            fieldType.pointDimensionCount(),
+            fieldType.pointIndexDimensionCount(),
+            fieldType.pointNumBytes());
+      }
+
       addAttributes(fi);
     }
     FieldInfos infos = builder.finish();
@@ -272,7 +287,7 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
     FieldType type = new FieldType();
     
     if (r.nextBoolean()) {
-      IndexOptions values[] = IndexOptions.values();
+      IndexOptions[] values = IndexOptions.values();
       type.setIndexOptions(values[r.nextInt(values.length)]);
       type.setOmitNorms(r.nextBoolean());
       
@@ -289,30 +304,23 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes
     }
     
     if (r.nextBoolean()) {
-      DocValuesType values[] = getDocValuesTypes();
+      DocValuesType[] values = DocValuesType.values();
       type.setDocValuesType(values[r.nextInt(values.length)]);
     }
-        
+
+    if (r.nextBoolean()) {
+      int dimension = 1 + r.nextInt(PointValues.MAX_DIMENSIONS);
+      int indexDimension = 1 + r.nextInt(Math.min(dimension, PointValues.MAX_INDEX_DIMENSIONS));
+      int dimensionNumBytes = 1 + r.nextInt(PointValues.MAX_NUM_BYTES);
+      type.setDimensions(dimension, indexDimension, dimensionNumBytes);
+    }
+
     return type;
   }
-  
-  /** 
-   * Hook to add any codec attributes to fieldinfo
-   * instances added in this test.
-   */
-  protected void addAttributes(FieldInfo fi) {
-  }
-  
-  /** 
-   * Docvalues types to test. 
-   * @deprecated only for Only available to ancient codecs can 
-   * limit this to the subset of types they support.
-   */
-  @Deprecated
-  protected DocValuesType[] getDocValuesTypes() {
-    return DocValuesType.values();
-  }
-  
+
+  /** Hook to add any codec attributes to fieldinfo instances added in this test. */
+  protected void addAttributes(FieldInfo fi) {}
+
   /** equality for entirety of fieldinfos */
   protected void assertEquals(FieldInfos expected, FieldInfos actual) {
     assertEquals(expected.size(), actual.size());