Apache Lucene open-source search software
SOLR-6183: bug, BBoxField didn't propagate docValues configuration. And numberType is now a required attribute.
David Wayne Smiley4a7b55d2586c
diff --git a/solr/core/src/java/org/apache/solr/schema/BBoxField.java b/solr/core/src/java/org/apache/solr/schema/BBoxField.javaindex 4ba36838342..422b35f89b6 100644--- a/solr/core/src/java/org/apache/solr/schema/BBoxField.java+++ b/solr/core/src/java/org/apache/solr/schema/BBoxField.java@@ -18,11 +18,13 @@ package org.apache.solr.schema;*/import com.spatial4j.core.shape.Rectangle;+import org.apache.lucene.index.FieldInfo;import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.spatial.bbox.BBoxOverlapRatioValueSource;import org.apache.lucene.spatial.bbox.BBoxStrategy;import org.apache.lucene.spatial.query.SpatialArgs;import org.apache.lucene.spatial.util.ShapeAreaValueSource;+import org.apache.solr.common.SolrException;import org.apache.solr.search.QParser;import java.util.ArrayList;@@ -32,7 +34,7 @@ import java.util.Map;public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implements SchemaAware {private static final String PARAM_QUERY_TARGET_PROPORTION = "queryTargetProportion";private static final String PARAM_MIN_SIDE_LENGTH = "minSideLength";- private String numberFieldName = "tdouble";+ private String numberFieldName;//requiredprivate String booleanFieldName = "boolean";private IndexSchema schema;@@ -42,9 +44,11 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implementssuper.init(schema, args);String v = args.remove("numberType");- if (v != null) {- numberFieldName = v;+ if (v == null) {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "The field type: " + typeName+ + " must specify the numberType attribute.");}+ numberFieldName = v;v = args.remove("booleanType");if (v != null) {@@ -92,9 +96,16 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implements@Overrideprotected BBoxStrategy newSpatialStrategy(String s) {BBoxStrategy strategy = new BBoxStrategy(ctx, s);- //Solr's FieldType ought to expose Lucene FieldType. Instead as a hack we create a field with a dummy value.+ //Solr's FieldType ought to expose Lucene FieldType. Instead as a hack we create a Field with a dummy value.SchemaField field = schema.getField(strategy.getFieldName() + BBoxStrategy.SUFFIX_MINX);- strategy.setFieldType((org.apache.lucene.document.FieldType) field.createField(0.0, 1.0f).fieldType());+ org.apache.lucene.document.FieldType luceneType =+ (org.apache.lucene.document.FieldType) field.createField(0.0, 1.0f).fieldType();+ //and annoyingly this field isn't going to have a docValues format because Solr uses a separate Field for that+ if (field.hasDocValues()) {+ luceneType = new org.apache.lucene.document.FieldType(luceneType);+ luceneType.setDocValueType(FieldInfo.DocValuesType.NUMERIC);+ }+ strategy.setFieldType(luceneType);return strategy;}diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.javaindex 27dfe5b8069..1e684c07d8d 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java@@ -17,12 +17,15 @@ package org.apache.solr.search;* limitations under the License.*/+import org.apache.lucene.util.LuceneTestCase;import org.apache.solr.SolrTestCaseJ4;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;//Unlike TestSolr4Spatial, not parameterized / not generic.+//We exclude Codecs that don't support DocValues (though not sure if this list is quite right)[email protected]({"Lucene3x", "Appending", "Lucene40", "Lucene41"})public class TestSolr4Spatial2 extends SolrTestCaseJ4 {@BeforeClassdiff --git a/solr/example/solr/collection1/conf/schema.xml b/solr/example/solr/collection1/conf/schema.xmlindex daf30340364..99022e7cc7b 100755--- a/solr/example/solr/collection1/conf/schema.xml+++ b/solr/example/solr/collection1/conf/schema.xml@@ -709,9 +709,11 @@geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" /><!-- Spatial rectangle (bounding box) field. It supports most spatial predicates, and has- special relevancy modes: score=overlapRatio|area|area2D (local-param to the query)-->+ special relevancy modes: score=overlapRatio|area|area2D (local-param to the query). DocValues is recommended for+ relevancy. --><fieldType name="bbox" class="solr.BBoxField"- geo="true" units="degrees" numberType="tdouble" />+ geo="true" units="degrees" numberType="_bbox_coord" />+ <fieldType name="_bbox_coord" class="solr.TrieDoubleField" precisionStep="8" docValues="true" stored="false"/><!-- Money/currency field type. See http://wiki.apache.org/solr/MoneyFieldTypeParameters: