[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:
parent
25914ae879
commit
d027ceb76d
|
@ -21,6 +21,7 @@ package org.elasticsearch.common.geo;
|
||||||
|
|
||||||
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
||||||
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
|
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
|
||||||
|
import org.apache.lucene.util.GeoDistanceUtils;
|
||||||
import org.apache.lucene.util.SloppyMath;
|
import org.apache.lucene.util.SloppyMath;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
|
@ -65,19 +66,11 @@ public class GeoUtils {
|
||||||
/** Earth ellipsoid polar distance in meters */
|
/** Earth ellipsoid polar distance in meters */
|
||||||
public static final double EARTH_POLAR_DISTANCE = Math.PI * EARTH_SEMI_MINOR_AXIS;
|
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
|
/** Returns the minimum between the provided distance 'initialRadius' and the
|
||||||
* maximum distance/radius from the point 'center' before overlapping
|
* maximum distance/radius from the point 'center' before overlapping
|
||||||
**/
|
**/
|
||||||
public static double maxRadialDistance(GeoPoint center, double initialRadius) {
|
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);
|
return Math.min(initialRadius, maxRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
|
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.apache.lucene.util.GeoDistanceUtils;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.geo.GeoDistance;
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
@ -263,7 +264,7 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
||||||
toValue = geoDistance.normalize(toValue, DistanceUnit.DEFAULT);
|
toValue = geoDistance.normalize(toValue, DistanceUnit.DEFAULT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toValue = GeoUtils.maxRadialDistance(point);
|
toValue = GeoDistanceUtils.maxRadialDistanceMeters(point.lon(), point.lat());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexCreatedBeforeV2_2 == true) {
|
if (indexCreatedBeforeV2_2 == true) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
|
import org.apache.lucene.search.GeoPointDistanceRangeQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.apache.lucene.util.GeoDistanceUtils;
|
||||||
import org.apache.lucene.util.NumericUtils;
|
import org.apache.lucene.util.NumericUtils;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.geo.GeoDistance;
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
@ -54,7 +55,7 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GeoPoint point = builder.point();
|
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 fromValueMeters = randomInt((int)(maxRadius*0.5));
|
||||||
final int toValueMeters = randomIntBetween(fromValueMeters + 1, (int)maxRadius);
|
final int toValueMeters = randomIntBetween(fromValueMeters + 1, (int)maxRadius);
|
||||||
DistanceUnit fromToUnits = randomFrom(DistanceUnit.values());
|
DistanceUnit fromToUnits = randomFrom(DistanceUnit.values());
|
||||||
|
|
Loading…
Reference in New Issue