SOLR-3864 maxDetailDist -> maxDistErr and make units='degrees' mandatory

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1388864 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2012-09-22 18:27:44 +00:00
parent a3f6ab1ea2
commit 255e8f1aa8
4 changed files with 18 additions and 13 deletions

View File

@ -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<String, String> args;
protected SpatialContext ctx;
@ -42,7 +45,7 @@ public abstract class SpatialPrefixTreeFactory {
*/
public static SpatialPrefixTree makeSPT(Map<String,String> 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);
}

View File

@ -62,6 +62,11 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
protected void init(IndexSchema schema, Map<String, String> 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<String, String> argsWrap = new MapListener<String, String>(args);
ctx = SpatialContextFactory.makeSpatialContext(argsWrap, schema.getResourceLoader().getClassLoader());

View File

@ -27,22 +27,22 @@
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
<fieldType name="srpt_geohash" class="solr.SpatialRecursivePrefixTreeFieldType"
prefixTree="geohash"
prefixTree="geohash" units="degrees"
/>
<fieldType name="srpt_quad" class="solr.SpatialRecursivePrefixTreeFieldType"
prefixTree="quad"
prefixTree="quad" units="degrees"
/>
<fieldType name="srpt_100km" class="solr.SpatialRecursivePrefixTreeFieldType"
maxDetailDist="0.9"
maxDistErr="0.9" units="degrees"
/>
<fieldType name="stqpt_geohash" class="solr.SpatialTermQueryPrefixTreeFieldType"
prefixTree="geohash" />
prefixTree="geohash" units="degrees" />
<fieldType name="stqpt_u" class="solr.SpatialTermQueryPrefixTreeFieldType"
geo="false" distCalculator="cartesian^2" worldBounds="0 0 1000 1000"/>
geo="false" distCalculator="cartesian^2" worldBounds="0 0 1000 1000" units="degrees"/>
<fieldType name="twodoubles" class="solr.SpatialTwoDoublesFieldType"
numberType="tdouble"/>
numberType="tdouble" units="degrees"/>
</types>

View File

@ -686,7 +686,7 @@
http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
-->
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
geo="true" distErrPct="0.025" maxDetailDist="0.000009" />
geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" />
<!-- Money/currency field type. See http://wiki.apache.org/solr/MoneyFieldType
Parameters: