mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
6386b22019
commit
4a7b55d258
|
@ -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;//required
|
||||
private String booleanFieldName = "boolean";
|
||||
|
||||
private IndexSchema schema;
|
||||
|
@ -42,9 +44,11 @@ public class BBoxField extends AbstractSpatialFieldType<BBoxStrategy> 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<BBoxStrategy> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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/MoneyFieldType
|
||||
Parameters:
|
||||
|
|
Loading…
Reference in New Issue