Skip to content

Apache Lucene open-source search software

SOLR-7164: BBoxFieldType defaults sub fields to not-stored

Ryan McKinley47662fff6031
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f53a23290e3..09204c8dce0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -117,6 +117,8 @@ New Features
* SOLR-5507: Admin UI - Refactoring using AngularJS, first part (Upayavira via
Erick Erickson)
+
+* SOLR-7164: BBoxFieldType defaults sub fields to not-stored (ryan)
Bug Fixes
----------------------
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 f9378afb5ef..4b42737c563 100644
--- a/solr/core/src/java/org/apache/solr/schema/BBoxField.java
+++ b/solr/core/src/java/org/apache/solr/schema/BBoxField.java
@@ -44,6 +44,7 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implements
private String numberTypeName;//required
private String booleanTypeName = "boolean";
+ private boolean storeSubFields = false;
private IndexSchema schema;
@@ -66,6 +67,11 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implements
if (v != null) {
booleanTypeName = v;
}
+
+ v = args.remove("storeSubFields");
+ if (v != null) {
+ storeSubFields = Boolean.valueOf(v);
+ }
}
@Override
@@ -108,7 +114,15 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> implements
// note: Registering the field is probably optional; it makes it show up in the schema browser and may have other
// benefits.
private void register(IndexSchema schema, String name, FieldType fieldType) {
- SchemaField sf = new SchemaField(name, fieldType);
+ int props = fieldType.properties;
+ props &= ~MULTIVALUED; // must not be multivalued
+ if(storeSubFields) {
+ props |= STORED;
+ }
+ else {
+ props &= ~STORED;
+ }
+ SchemaField sf = new SchemaField(name, fieldType, props, null);
schema.getFields().put(sf.getName(), sf);
}
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml b/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
index 673f3b3d862..5f5d856ca22 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
@@ -48,7 +48,7 @@
numberType="tdouble" distanceUnits="degrees"/>
<fieldType name="bbox" class="solr.BBoxField"
- numberType="tdoubleDV" distanceUnits="degrees"/>
+ numberType="tdoubleDV" distanceUnits="degrees" storeSubFields="false"/>
</types>
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
index c086b7ad4d0..f2334a76286 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial.java
@@ -26,8 +26,13 @@ import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;
+
+import org.apache.lucene.spatial.bbox.BBoxStrategy;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
+import org.apache.solr.schema.BBoxField;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.schema.SchemaField;
import org.apache.solr.util.SpatialUtils;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -366,4 +371,16 @@ public class TestSolr4Spatial extends SolrTestCaseJ4 {
SolrException.ErrorCode.BAD_REQUEST);
}
+
+ @Test
+ public void testSpatialConfig() throws Exception {
+ IndexSchema schema = h.getCoreInc().getLatestSchema();
+
+ // BBox Config
+ // Make sure the subfields are not stored
+ SchemaField sub = schema.getField("bbox"+BBoxStrategy.SUFFIX_MINX);
+ assertFalse(sub.stored());
+ assertFalse(sub.multiValued());
+ }
+
}