From 47662fff6031f5c6405c30d0dc34291c08b7a6ed Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 26 Feb 2015 04:38:36 +0000 Subject: [PATCH] SOLR-7164: BBoxFieldType defaults sub fields to not-stored git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662355 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 2 ++ .../java/org/apache/solr/schema/BBoxField.java | 16 +++++++++++++++- .../solr/collection1/conf/schema-spatial.xml | 2 +- .../apache/solr/search/TestSolr4Spatial.java | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) 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 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 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 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"/> + numberType="tdoubleDV" distanceUnits="degrees" storeSubFields="false"/> 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()); + } + }