You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2017/03/17 18:57:57 UTC

lucene-solr:master: SOLR-10237: Poly-Fields should work with subfield that have docValues=true

Repository: lucene-solr
Updated Branches:
  refs/heads/master 540ee1db1 -> 3b6600184


SOLR-10237: Poly-Fields should work with subfield that have docValues=true


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3b660018
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3b660018
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3b660018

Branch: refs/heads/master
Commit: 3b660018457234387558ff626c8b95bb6f4ce853
Parents: 540ee1d
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Fri Mar 17 11:55:15 2017 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Fri Mar 17 11:55:15 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../solr/schema/AbstractSubTypeFieldType.java   | 17 ++++++---
 .../java/org/apache/solr/schema/LatLonType.java | 12 +++++-
 .../java/org/apache/solr/schema/PointType.java  | 14 +++++--
 .../test-files/solr/collection1/conf/schema.xml | 15 ++++----
 .../org/apache/solr/schema/PolyFieldTest.java   | 40 ++++++++++++--------
 .../apache/solr/update/DocumentBuilderTest.java |  4 +-
 7 files changed, 68 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1548410..75ac5bb 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -303,6 +303,8 @@ Bug Fixes
 * SOLR-10283: Learning to Rank (LTR) SolrFeature to reject searches with missing efi (External Feature Information) used by fq.
   (Christine Poerschke)
 
+* SOLR-10237: Poly-fields should work with subfields that have docValues=true (Tom�s Fern�ndez L�bbe, David Smiley)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/java/org/apache/solr/schema/AbstractSubTypeFieldType.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/AbstractSubTypeFieldType.java b/solr/core/src/java/org/apache/solr/schema/AbstractSubTypeFieldType.java
index 1184876..73a4f3c 100644
--- a/solr/core/src/java/org/apache/solr/schema/AbstractSubTypeFieldType.java
+++ b/solr/core/src/java/org/apache/solr/schema/AbstractSubTypeFieldType.java
@@ -76,20 +76,25 @@ public abstract class AbstractSubTypeFieldType extends FieldType implements Sche
    * and props of indexed=true, stored=false.
    *
    * @param schema the IndexSchema
-   * @param type   The {@link FieldType} of the prototype.
+   * @param subType   The {@link FieldType} of the prototype.
+   * @param polyField   The poly {@link FieldType}.
    * @return The {@link SchemaField}
    */
 
-  static SchemaField registerPolyFieldDynamicPrototype(IndexSchema schema, FieldType type) {
-    String name = "*" + FieldType.POLY_FIELD_SEPARATOR + type.typeName;
+  static SchemaField registerPolyFieldDynamicPrototype(IndexSchema schema, FieldType subType, FieldType polyField) {
+    String name = "*" + FieldType.POLY_FIELD_SEPARATOR + subType.typeName;
     Map<String, String> props = new HashMap<>();
     //Just set these, delegate everything else to the field type
     props.put("indexed", "true");
     props.put("stored", "false");
     props.put("multiValued", "false");
-    int p = SchemaField.calcProps(name, type, props);
+    // if polyField enables dv, add them to the subtypes
+    if (polyField.hasProperty(DOC_VALUES)) {
+      props.put("docValues", "true");
+    }
+    int p = SchemaField.calcProps(name, subType, props);
     SchemaField proto = SchemaField.create(name,
-            type, p, null);
+        subType, p, null);
     schema.registerDynamicFields(proto);
     return proto;
   }
@@ -107,7 +112,7 @@ public abstract class AbstractSubTypeFieldType extends FieldType implements Sche
     this.schema = schema;
     //Can't do this until here b/c the Dynamic Fields are not initialized until here.
     if (subType != null) {
-      SchemaField proto = registerPolyFieldDynamicPrototype(schema, subType);
+      SchemaField proto = registerPolyFieldDynamicPrototype(schema, subType, this);
       dynFieldProps = proto.getProperties();
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/java/org/apache/solr/schema/LatLonType.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonType.java b/solr/core/src/java/org/apache/solr/schema/LatLonType.java
index c484f3a..8c4e19a 100644
--- a/solr/core/src/java/org/apache/solr/schema/LatLonType.java
+++ b/solr/core/src/java/org/apache/solr/schema/LatLonType.java
@@ -75,10 +75,10 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery
       Point point = SpatialUtils.parsePointSolrException(externalVal, SpatialContext.GEO);
       //latitude
       SchemaField subLatSF = subField(field, LAT, schema);
-      f.add(subLatSF.createField(String.valueOf(point.getY())));
+      f.addAll(subLatSF.createFields(String.valueOf(point.getY())));
       //longitude
       SchemaField subLonSF = subField(field, LON, schema);
-      f.add(subLonSF.createField(String.valueOf(point.getX())));
+      f.addAll(subLonSF.createFields(String.valueOf(point.getX())));
     }
 
     if (field.stored()) {
@@ -86,6 +86,14 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery
     }
     return f;
   }
+  
+  @Override
+  protected void checkSupportsDocValues() {
+    // DocValues supported only when enabled at the fieldType 
+    if (!hasProperty(DOC_VALUES)) {
+      throw new UnsupportedOperationException("LatLonType can't have docValues=true in the field definition, use docValues=true in the fieldType definition, or in subFieldType/subFieldSuffix");
+    }
+  }
 
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/java/org/apache/solr/schema/PointType.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/PointType.java b/solr/core/src/java/org/apache/solr/schema/PointType.java
index 4c022b8..e088e7f 100644
--- a/solr/core/src/java/org/apache/solr/schema/PointType.java
+++ b/solr/core/src/java/org/apache/solr/schema/PointType.java
@@ -71,12 +71,12 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable {
     String[] point = parseCommaSeparatedList(externalVal, dimension);
 
     // TODO: this doesn't currently support polyFields as sub-field types
-    List<IndexableField> f = new ArrayList<>(dimension+1);
+    List<IndexableField> f = new ArrayList<>((dimension*2)+1);
 
     if (field.indexed()) {
       for (int i=0; i<dimension; i++) {
         SchemaField sf = subField(field, i, schema);
-        f.add(sf.createField(point[i]));
+        f.addAll(sf.createFields(point[i]));
       }
     }
 
@@ -84,7 +84,7 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable {
       String storedVal = externalVal;  // normalize or not?
       f.add(createField(field.getName(), storedVal, StoredField.TYPE));
     }
-    
+
     return f;
   }
 
@@ -155,6 +155,14 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable {
     }
     return bq.build();
   }
+  
+  @Override
+  protected void checkSupportsDocValues() {
+    // DocValues supported only when enabled at the fieldType 
+    if (!hasProperty(DOC_VALUES)) {
+      throw new UnsupportedOperationException("PointType can't have docValues=true in the field definition, use docValues=true in the fieldType definition, or in subFieldType/subFieldSuffix");
+    }
+  }
 
   /**
    * Calculates the range and creates a RangeQuery (bounding box) wrapped in a BooleanQuery (unless the dimension is

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/test-files/solr/collection1/conf/schema.xml
----------------------------------------------------------------------
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema.xml b/solr/core/src/test-files/solr/collection1/conf/schema.xml
index 8c549a3..6f5eddc 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml
@@ -392,15 +392,14 @@
   <fieldType name="uuid" class="solr.UUIDField"/>
 
   <!-- Try out some point types -->
-  <fieldType name="xy" class="solr.PointType" dimension="2" subFieldType="double"/>
-  <fieldType name="x" class="solr.PointType" dimension="1" subFieldType="double"/>
-  <fieldType name="tenD" class="solr.PointType" dimension="10" subFieldType="double"/>
-  <!-- Use the sub field suffix -->
-  <fieldType name="xyd" class="solr.PointType" dimension="2" subFieldSuffix="_d1_ndv"/>
+  <fieldType name="xy" class="solr.PointType" dimension="2" subFieldType="${solr.tests.doubleClass:pdouble}"  docValues="true"/>
+  <fieldType name="x" class="solr.PointType" dimension="1" subFieldType="${solr.tests.doubleClass:pdouble}"/>
+  <fieldType name="tenD" class="solr.PointType" dimension="10" subFieldType="${solr.tests.doubleClass:pdouble}"/>
+  <fieldType name="xyd" class="solr.PointType" dimension="2" subFieldSuffix="_d1"/>
   <fieldType name="geohash" class="solr.GeoHashField"/>
 
 
-  <fieldType name="latLon" class="solr.LatLonType" subFieldType="double"/>
+  <fieldType name="latLon" class="solr.LatLonType" subFieldType="${solr.tests.doubleClass:pdouble}"/>
 
   <!-- Currency type -->
   <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml" multiValued="false"/>
@@ -621,7 +620,7 @@
   <dynamicField name="*_f1" type="${solr.tests.floatClass:pfloat}" indexed="true" stored="true" multiValued="false"/>
   <dynamicField name="*_d" type="${solr.tests.doubleClass:pdouble}" indexed="true" stored="true"/>
   <dynamicField name="*_d1" type="${solr.tests.doubleClass:pdouble}" indexed="true" stored="true" multiValued="false"/>
-  <dynamicField name="*_d1_ndv" type="${solr.tests.doubleClass:pdouble}" indexed="true" docValues="false" stored="true" multiValued="false"/>
+  <dynamicField name="*_d1_dv" type="${solr.tests.doubleClass:pdouble}" indexed="true" docValues="true" stored="true" multiValued="false"/>
   <dynamicField name="*_dt" type="${solr.tests.dateClass:pdate}" indexed="true" stored="true"/>
   <dynamicField name="*_dt1" type="${solr.tests.dateClass:pdate}" indexed="true" stored="true" multiValued="false"/>
 
@@ -671,7 +670,7 @@
   <dynamicField name="*_mfacet" type="string" indexed="true" stored="false" multiValued="true"/>
 
   <!-- Type used to index the lat and lon components for the "location" FieldType -->
-  <dynamicField name="*_coordinate" type="${solr.tests.doubleClass:pdouble}" indexed="true" stored="false" omitNorms="true"/>
+  <dynamicField name="*_coordinate" type="${solr.tests.doubleClass:pdouble}" indexed="true" stored="false" omitNorms="true" docValues="false"/>
 
   <dynamicField name="*_path" type="path" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
   <dynamicField name="*_ancestor" type="ancestor_path" indexed="true" stored="true" omitNorms="true"

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java b/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java
index 6839c70..900e439 100644
--- a/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.solr.schema;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.lucene.index.IndexableField;
@@ -45,11 +46,16 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
     SchemaField home = schema.getField("home");
     assertNotNull(home);
     assertTrue(home.isPolyField());
+    
+    String subFieldType = "double";
+    if (usingPointFields()) {
+      subFieldType = "pdouble";
+    }
 
     SchemaField[] dynFields = schema.getDynamicFieldPrototypes();
     boolean seen = false;
     for (SchemaField dynField : dynFields) {
-      if (dynField.getName().equals("*" + FieldType.POLY_FIELD_SEPARATOR + "double")) {
+      if (dynField.getName().equals("*" + FieldType.POLY_FIELD_SEPARATOR + subFieldType)) {
         seen = true;
       }
     }
@@ -60,7 +66,7 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
     assertNotNull(xy);
     assertTrue(xy instanceof PointType);
     assertTrue(xy.isPolyField());
-    home = schema.getFieldOrNull("home_0" + FieldType.POLY_FIELD_SEPARATOR + "double");
+    home = schema.getFieldOrNull("home_0" + FieldType.POLY_FIELD_SEPARATOR + subFieldType);
     assertNotNull(home);
     home = schema.getField("home");
     assertNotNull(home);
@@ -84,9 +90,14 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
     double[] xy = new double[]{35.0, -79.34};
     String point = xy[0] + "," + xy[1];
     List<IndexableField> fields = home.createFields(point);
-    assertEquals(fields.size(), 3);//should be 3, we have a stored field
-    //first two fields contain the values, third is just stored and contains the original
-    for (int i = 0; i < 3; i++) {
+    assertNotNull(pt.getSubType());
+    int expectdNumFields = 3;//If DV=false, we expect one field per dimension plus a stored field
+    if (pt.subField(home, 0, schema).hasDocValues()) {
+      expectdNumFields+=2; // If docValues=true, then we expect two more fields
+    }
+    assertEquals("Unexpected fields created: " + Arrays.toString(fields.toArray()), expectdNumFields, fields.size());
+    //first two/four fields contain the values, last one is just stored and contains the original
+    for (int i = 0; i < expectdNumFields; i++) {
       boolean hasValue = fields.get(i).binaryValue() != null
           || fields.get(i).stringValue() != null
           || fields.get(i).numericValue() != null;
@@ -100,7 +111,7 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
     home = schema.getField("home_ns");
     assertNotNull(home);
     fields = home.createFields(point);
-    assertEquals(fields.size(), 2);//should be 2, since we aren't storing
+    assertEquals(expectdNumFields - 1, fields.size(), 2);//one less field than with "home", since we aren't storing
 
     home = schema.getField("home_ns");
     assertNotNull(home);
@@ -111,17 +122,12 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
       //
     }
 
-    
     SchemaField s1 = schema.getField("test_p");
     SchemaField s2 = schema.getField("test_p");
-    // If we use [Int/Double/Long/Float]PointField, we can't get the valueSource, since docValues is false
-    if (s1.createFields("1,2").get(0).fieldType().pointDimensionCount() == 0) {
-      assertFalse(s2.getType().isPointField());
-      ValueSource v1 = s1.getType().getValueSource(s1, null);
-      ValueSource v2 = s2.getType().getValueSource(s2, null);
-      assertEquals(v1, v2);
-      assertEquals(v1.hashCode(), v2.hashCode());
-    }
+    ValueSource v1 = s1.getType().getValueSource(s1, null);
+    ValueSource v2 = s2.getType().getValueSource(s2, null);
+    assertEquals(v1, v2);
+    assertEquals(v1.hashCode(), v2.hashCode());
   }
 
   @Test
@@ -181,5 +187,9 @@ public class PolyFieldTest extends SolrTestCaseJ4 {
     assertEquals(2, bq.clauses().size());
     clearIndex();
   }
+  
+  private boolean usingPointFields() {
+    return h.getCore().getLatestSchema().getField("foo_d1_dv").getType().isPointField();
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3b660018/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
index 03dd17c..5d98d8b 100644
--- a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
+++ b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
@@ -131,8 +131,8 @@ public class DocumentBuilderTest extends SolrTestCaseJ4 {
     doc.addField( "home", "2.2,3.3" );
     Document out = DocumentBuilder.toDocument( doc, core.getLatestSchema() );
     assertNotNull( out.get( "home" ) );//contains the stored value and term vector, if there is one
-    assertNotNull( out.getField( "home_0" + FieldType.POLY_FIELD_SEPARATOR + "double" ) );
-    assertNotNull( out.getField( "home_1" + FieldType.POLY_FIELD_SEPARATOR + "double" ) );
+    assertNotNull( out.getField( "home_0" + FieldType.POLY_FIELD_SEPARATOR + System.getProperty("solr.tests.doubleClass", "pdouble") ) );
+    assertNotNull( out.getField( "home_1" + FieldType.POLY_FIELD_SEPARATOR + System.getProperty("solr.tests.doubleClass", "pdouble") ) );
   }
   
   /**