[TEST] Update GeoDistanceQuery to use Lucene's maxRadialDistance

Removing maxRadialDistance method from ES GeoUtils in favor of Lucene 5.4 GeoDistanceUtils.maxRadialDistanceMeters.
This commit is contained in:
Nicholas Knize 2015-12-29 09:47:59 -06:00
parent 25914ae879
commit d027ceb76d
3 changed files with 6 additions and 11 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.common.geo;
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.util.GeoDistanceUtils;
import org.apache.lucene.util.SloppyMath;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.unit.DistanceUnit;
@ -65,19 +66,11 @@ public class GeoUtils {
/** Earth ellipsoid polar distance in meters */
public static final double EARTH_POLAR_DISTANCE = Math.PI * EARTH_SEMI_MINOR_AXIS;
/** Returns the maximum distance/radius from the point 'center' before overlapping */
public static double maxRadialDistance(GeoPoint center) {
if (Math.abs(center.lat()) == 90.0) {
return SloppyMath.haversin(center.lat(), center.lon(), 0, center.lon())*1000.0;
}
return SloppyMath.haversin(center.lat(), center.lon(), center.lat(), (180.0 + center.lon()) % 360)*1000.0;
}
/** Returns the minimum between the provided distance 'initialRadius' and the
* maximum distance/radius from the point 'center' before overlapping
**/
public static double maxRadialDistance(GeoPoint center, double initialRadius) {
final double maxRadius = maxRadialDistance(center);
final double maxRadius = GeoDistanceUtils.maxRadialDistanceMeters(center.lon(), center.lat());
return Math.min(initialRadius, maxRadius);
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.GeoDistanceUtils;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.geo.GeoDistance;
@ -263,7 +264,7 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
toValue = geoDistance.normalize(toValue, DistanceUnit.DEFAULT);
}
} else {
toValue = GeoUtils.maxRadialDistance(point);
toValue = GeoDistanceUtils.maxRadialDistanceMeters(point.lon(), point.lat());
}
if (indexCreatedBeforeV2_2 == true) {

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.GeoDistanceUtils;
import org.apache.lucene.util.NumericUtils;
import org.elasticsearch.Version;
import org.elasticsearch.common.geo.GeoDistance;
@ -54,7 +55,7 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
}
}
GeoPoint point = builder.point();
final double maxRadius = GeoUtils.maxRadialDistance(point);
final double maxRadius = GeoDistanceUtils.maxRadialDistanceMeters(point.lon(), point.lat());
final int fromValueMeters = randomInt((int)(maxRadius*0.5));
final int toValueMeters = randomIntBetween(fromValueMeters + 1, (int)maxRadius);
DistanceUnit fromToUnits = randomFrom(DistanceUnit.values());