You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2014/11/25 04:53:10 UTC
svn commit: r1641524 - in /lucene/dev/branches/lucene_solr_4_10: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/schema/
solr/core/src/test-files/solr/collection1/conf/
solr/core/src/test/org/apache/solr/search/
Author: dsmiley
Date: Tue Nov 25 03:53:09 2014
New Revision: 1641524
URL: http://svn.apache.org/r1641524
Log:
SOLR-6781: Bugfix- BBoxField didn't support dynamic fields.
Modified:
lucene/dev/branches/lucene_solr_4_10/ (props changed)
lucene/dev/branches/lucene_solr_4_10/solr/ (props changed)
lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/lucene_solr_4_10/solr/core/ (props changed)
lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/schema/BBoxField.java
lucene/dev/branches/lucene_solr_4_10/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
lucene/dev/branches/lucene_solr_4_10/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
Modified: lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt?rev=1641524&r1=1641523&r2=1641524&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/CHANGES.txt Tue Nov 25 03:53:09 2014
@@ -48,6 +48,8 @@ Bug Fixes
and is now a JSON map, caused backwards compatibility issues when doing rolling upgrades of
a live cluster while indexing (Timothy Potter)
+* SOLR-6781: BBoxField didn't support dynamic fields. (David Smiley)
+
Other Changes
----------------------
Modified: lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/schema/BBoxField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/schema/BBoxField.java?rev=1641524&r1=1641523&r2=1641524&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/schema/BBoxField.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/core/src/java/org/apache/solr/schema/BBoxField.java Tue Nov 25 03:53:09 2014
@@ -34,8 +34,8 @@ 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;//required
- private String booleanFieldName = "boolean";
+ private String numberTypeName;//required
+ private String booleanTypeName = "boolean";
private IndexSchema schema;
@@ -48,25 +48,25 @@ public class BBoxField extends AbstractS
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "The field type: " + typeName
+ " must specify the numberType attribute.");
}
- numberFieldName = v;
+ numberTypeName = v;
v = args.remove("booleanType");
if (v != null) {
- booleanFieldName = v;
+ booleanTypeName = v;
}
}
@Override
public void inform(IndexSchema schema) {
this.schema = schema;
- FieldType numberType = schema.getFieldTypeByName(numberFieldName);
- FieldType booleanType = schema.getFieldTypeByName(booleanFieldName);
+ FieldType numberType = schema.getFieldTypeByName(numberTypeName);
+ FieldType booleanType = schema.getFieldTypeByName(booleanTypeName);
if (numberType == null) {
- throw new RuntimeException("Cannot find number fieldType: " + numberFieldName);
+ throw new RuntimeException("Cannot find number fieldType: " + numberTypeName);
}
if (booleanType == null) {
- throw new RuntimeException("Cannot find boolean fieldType: " + booleanFieldName);
+ throw new RuntimeException("Cannot find boolean fieldType: " + booleanTypeName);
}
if (!(booleanType instanceof BoolField)) {
throw new RuntimeException("Must be a BoolField: " + booleanType);
@@ -75,33 +75,47 @@ public class BBoxField extends AbstractS
throw new RuntimeException("Must be TrieDoubleField: " + numberType);
}
+ //note: this only works for explicit fields, not dynamic fields
List<SchemaField> fields = new ArrayList<>(schema.getFields().values());//copy, because we modify during iteration
for (SchemaField sf : fields) {
if (sf.getType() == this) {
String name = sf.getName();
- register(schema, name + BBoxStrategy.SUFFIX_MINX, numberType);
- register(schema, name + BBoxStrategy.SUFFIX_MAXX, numberType);
- register(schema, name + BBoxStrategy.SUFFIX_MINY, numberType);
- register(schema, name + BBoxStrategy.SUFFIX_MAXY, numberType);
- register(schema, name + BBoxStrategy.SUFFIX_XDL, booleanType);
+ registerSubFields(schema, name, numberType, booleanType);
}
}
}
+ private void registerSubFields(IndexSchema schema, String name, FieldType numberType, FieldType booleanType) {
+ register(schema, name + BBoxStrategy.SUFFIX_MINX, numberType);
+ register(schema, name + BBoxStrategy.SUFFIX_MAXX, numberType);
+ register(schema, name + BBoxStrategy.SUFFIX_MINY, numberType);
+ register(schema, name + BBoxStrategy.SUFFIX_MAXY, numberType);
+ register(schema, name + BBoxStrategy.SUFFIX_XDL, booleanType);
+ }
+
+ // 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);
schema.getFields().put(sf.getName(), sf);
}
@Override
- protected BBoxStrategy newSpatialStrategy(String s) {
- BBoxStrategy strategy = new BBoxStrategy(ctx, s);
+ protected BBoxStrategy newSpatialStrategy(String fieldName) {
+ //if it's a dynamic field, we register the sub-fields now.
+ FieldType numberType = schema.getFieldTypeByName(numberTypeName);
+ FieldType booleanType = schema.getFieldTypeByName(booleanTypeName);
+ if (schema.isDynamicField(fieldName)) {
+ registerSubFields(schema, fieldName, numberType, booleanType);
+ }
+
+ BBoxStrategy strategy = new BBoxStrategy(ctx, fieldName);
//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);
+ final SchemaField solrNumField = new SchemaField("_", numberType);//dummy temp
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()) {
+ (org.apache.lucene.document.FieldType) solrNumField.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 (solrNumField.hasDocValues()) {
luceneType = new org.apache.lucene.document.FieldType(luceneType);
luceneType.setDocValueType(FieldInfo.DocValuesType.NUMERIC);
}
Modified: lucene/dev/branches/lucene_solr_4_10/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml?rev=1641524&r1=1641523&r2=1641524&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/core/src/test-files/solr/collection1/conf/schema-spatial.xml Tue Nov 25 03:53:09 2014
@@ -65,6 +65,8 @@
<field name="pointvector" type="pointvector" />
<field name="bbox" type="bbox" />
+ <dynamicField name="bboxD_*" type="bbox" indexed="true" />
+
</fields>
<uniqueKey>id</uniqueKey>
Modified: lucene/dev/branches/lucene_solr_4_10/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java?rev=1641524&r1=1641523&r2=1641524&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/solr/core/src/test/org/apache/solr/search/TestSolr4Spatial2.java Tue Nov 25 03:53:09 2014
@@ -42,7 +42,7 @@ public class TestSolr4Spatial2 extends S
@Test
public void testBBox() throws Exception {
- String fieldName = "bbox";
+ String fieldName = random().nextBoolean() ? "bbox" : "bboxD_dynamic";
assertU(adoc("id", "0"));//nothing
assertU(adoc("id", "1", fieldName, "ENVELOPE(-10, 20, 15, 10)"));
assertU(adoc("id", "2", fieldName, "ENVELOPE(22, 22, 10, 10)"));//pt
@@ -51,14 +51,16 @@ public class TestSolr4Spatial2 extends S
assertJQ(req("q", "{!field f="+fieldName+" filter=false score=overlapRatio " +
"queryTargetProportion=0.25}" +
"Intersects(ENVELOPE(10,25,12,10))",
- "fl", "id,score",
+ "fl", "*,score",
"debug", "results"),//explain info
"/response/docs/[0]/id=='2'",
"/response/docs/[0]/score==0.75]",
"/response/docs/[1]/id=='1'",
"/response/docs/[1]/score==0.26666668]",
"/response/docs/[2]/id=='0'",
- "/response/docs/[2]/score==0.0"
+ "/response/docs/[2]/score==0.0",
+
+ "/response/docs/[1]/" + fieldName + "=='ENVELOPE(-10, 20, 15, 10)'"//stored value
);
//minSideLength with point query