From 4a7b55d2586cdf093d1d43331cbfee978dad4538 Mon Sep 17 00:00:00 2001 From: David Wayne Smiley Date: Wed, 9 Jul 2014 20:31:37 +0000 Subject: [PATCH] SOLR-6183: bug, BBoxField didn't propagate docValues configuration. And numberType is now a required attribute. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1609291 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/schema/BBoxField.java | 21 ++++++++++++++----- .../apache/solr/search/TestSolr4Spatial2.java | 3 +++ solr/example/solr/collection1/conf/schema.xml | 6 ++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/schema/BBoxField.java b/solr/core/src/java/org/apache/solr/schema/BBoxField.java index 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 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;//required private String booleanFieldName = "boolean"; private IndexSchema schema; @@ -42,9 +44,11 @@ public class BBoxField extends AbstractSpatialFieldType implements super.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 implements @Override protected 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.java index 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) +@LuceneTestCase.SuppressCodecs({"Lucene3x", "Appending", "Lucene40", "Lucene41"}) public class TestSolr4Spatial2 extends SolrTestCaseJ4 { @BeforeClass diff --git a/solr/example/solr/collection1/conf/schema.xml b/solr/example/solr/collection1/conf/schema.xml index 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" /> + special relevancy modes: score=overlapRatio|area|area2D (local-param to the query). DocValues is recommended for + relevancy. --> + geo="true" units="degrees" numberType="_bbox_coord" /> +