diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeFactory.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeFactory.java index bbb01df0d22..f5a4bc49426 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeFactory.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeFactory.java @@ -31,6 +31,9 @@ import java.util.Map; public abstract class SpatialPrefixTreeFactory { private static final double DEFAULT_GEO_MAX_DETAIL_KM = 0.001;//1m + public static final String PREFIX_TREE = "prefixTree"; + public static final String MAX_LEVELS = "maxLevels"; + public static final String MAX_DIST_ERR = "maxDistErr"; protected Map args; protected SpatialContext ctx; @@ -42,7 +45,7 @@ public abstract class SpatialPrefixTreeFactory { */ public static SpatialPrefixTree makeSPT(Map args, ClassLoader classLoader, SpatialContext ctx) { SpatialPrefixTreeFactory instance; - String cname = args.get("prefixTree"); + String cname = args.get(PREFIX_TREE); if (cname == null) cname = ctx.isGeo() ? "geohash" : "quad"; if ("geohash".equalsIgnoreCase(cname)) @@ -68,14 +71,14 @@ public abstract class SpatialPrefixTreeFactory { } protected void initMaxLevels() { - String mlStr = args.get("maxLevels"); + String mlStr = args.get(MAX_LEVELS); if (mlStr != null) { maxLevels = Integer.valueOf(mlStr); return; } double degrees; - String maxDetailDistStr = args.get("maxDetailDist"); + String maxDetailDistStr = args.get(MAX_DIST_ERR); if (maxDetailDistStr == null) { if (!ctx.isGeo()) { return;//let default to max @@ -83,9 +86,6 @@ public abstract class SpatialPrefixTreeFactory { degrees = DistanceUtils.dist2Degrees(DEFAULT_GEO_MAX_DETAIL_KM, DistanceUtils.EARTH_MEAN_RADIUS_KM); } else { degrees = Double.parseDouble(maxDetailDistStr); - if (ctx.isGeo()) { - degrees = DistanceUtils.dist2Degrees(Double.parseDouble(maxDetailDistStr), DistanceUtils.EARTH_MEAN_RADIUS_KM); - } } maxLevels = getLevelForDistance(degrees); } diff --git a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java index 90c9b943736..7ed8640910e 100644 --- a/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/AbstractSpatialFieldType.java @@ -62,6 +62,11 @@ public abstract class AbstractSpatialFieldType extend protected void init(IndexSchema schema, Map args) { super.init(schema, args); + String units = args.remove("units"); + if (!"degrees".equals(units)) + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, + "Must specify units=\"degrees\" on field types with class "+getClass().getSimpleName()); + //Solr expects us to remove the parameters we've used. MapListener argsWrap = new MapListener(args); ctx = SpatialContextFactory.makeSpatialContext(argsWrap, schema.getResourceLoader().getClassLoader()); 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 e094c7238f4..266873b6004 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 @@ -27,22 +27,22 @@ + prefixTree="geohash" units="degrees" /> + geo="false" distCalculator="cartesian^2" worldBounds="0 0 1000 1000" units="degrees"/> + numberType="tdouble" units="degrees"/> diff --git a/solr/example/solr/collection1/conf/schema.xml b/solr/example/solr/collection1/conf/schema.xml index b34f9969075..caaf5036dce 100755 --- a/solr/example/solr/collection1/conf/schema.xml +++ b/solr/example/solr/collection1/conf/schema.xml @@ -686,7 +686,7 @@ http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 --> + geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" />