refactor geo to extract common classes
This commit is contained in:
parent
9c729fad2c
commit
a74e7f8099
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.index.search.geo;
|
package org.elasticsearch.common.geo;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
|
@ -136,8 +136,8 @@ public enum GeoDistance {
|
||||||
maxLon = MAX_LON;
|
maxLon = MAX_LON;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point topLeft = new Point(Math.toDegrees(maxLat), Math.toDegrees(minLon));
|
GeoPoint topLeft = new GeoPoint(Math.toDegrees(maxLat), Math.toDegrees(minLon));
|
||||||
Point bottomRight = new Point(Math.toDegrees(minLat), Math.toDegrees(maxLon));
|
GeoPoint bottomRight = new GeoPoint(Math.toDegrees(minLat), Math.toDegrees(maxLon));
|
||||||
if (minLon > maxLon) {
|
if (minLon > maxLon) {
|
||||||
return new Meridian180DistanceBoundingCheck(topLeft, bottomRight);
|
return new Meridian180DistanceBoundingCheck(topLeft, bottomRight);
|
||||||
}
|
}
|
||||||
|
@ -164,9 +164,9 @@ public enum GeoDistance {
|
||||||
|
|
||||||
boolean isWithin(double targetLatitude, double targetLongitude);
|
boolean isWithin(double targetLatitude, double targetLongitude);
|
||||||
|
|
||||||
Point topLeft();
|
GeoPoint topLeft();
|
||||||
|
|
||||||
Point bottomRight();
|
GeoPoint bottomRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AlwaysDistanceBoundingCheck ALWAYS_INSTANCE = new AlwaysDistanceBoundingCheck();
|
public static AlwaysDistanceBoundingCheck ALWAYS_INSTANCE = new AlwaysDistanceBoundingCheck();
|
||||||
|
@ -178,65 +178,65 @@ public enum GeoDistance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point topLeft() {
|
public GeoPoint topLeft() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point bottomRight() {
|
public GeoPoint bottomRight() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Meridian180DistanceBoundingCheck implements DistanceBoundingCheck {
|
public static class Meridian180DistanceBoundingCheck implements DistanceBoundingCheck {
|
||||||
|
|
||||||
private final Point topLeft;
|
private final GeoPoint topLeft;
|
||||||
private final Point bottomRight;
|
private final GeoPoint bottomRight;
|
||||||
|
|
||||||
public Meridian180DistanceBoundingCheck(Point topLeft, Point bottomRight) {
|
public Meridian180DistanceBoundingCheck(GeoPoint topLeft, GeoPoint bottomRight) {
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
this.bottomRight = bottomRight;
|
this.bottomRight = bottomRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(double targetLatitude, double targetLongitude) {
|
public boolean isWithin(double targetLatitude, double targetLongitude) {
|
||||||
return (targetLatitude >= bottomRight.lat && targetLatitude <= topLeft.lat) &&
|
return (targetLatitude >= bottomRight.lat() && targetLatitude <= topLeft.lat()) &&
|
||||||
(targetLongitude >= topLeft.lon || targetLongitude <= bottomRight.lon);
|
(targetLongitude >= topLeft.lon() || targetLongitude <= bottomRight.lon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point topLeft() {
|
public GeoPoint topLeft() {
|
||||||
return topLeft;
|
return topLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point bottomRight() {
|
public GeoPoint bottomRight() {
|
||||||
return bottomRight;
|
return bottomRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SimpleDistanceBoundingCheck implements DistanceBoundingCheck {
|
public static class SimpleDistanceBoundingCheck implements DistanceBoundingCheck {
|
||||||
private final Point topLeft;
|
private final GeoPoint topLeft;
|
||||||
private final Point bottomRight;
|
private final GeoPoint bottomRight;
|
||||||
|
|
||||||
public SimpleDistanceBoundingCheck(Point topLeft, Point bottomRight) {
|
public SimpleDistanceBoundingCheck(GeoPoint topLeft, GeoPoint bottomRight) {
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
this.bottomRight = bottomRight;
|
this.bottomRight = bottomRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(double targetLatitude, double targetLongitude) {
|
public boolean isWithin(double targetLatitude, double targetLongitude) {
|
||||||
return (targetLatitude >= bottomRight.lat && targetLatitude <= topLeft.lat) &&
|
return (targetLatitude >= bottomRight.lat() && targetLatitude <= topLeft.lat()) &&
|
||||||
(targetLongitude >= topLeft.lon && targetLongitude <= bottomRight.lon);
|
(targetLongitude >= topLeft.lon() && targetLongitude <= bottomRight.lon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point topLeft() {
|
public GeoPoint topLeft() {
|
||||||
return topLeft;
|
return topLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point bottomRight() {
|
public GeoPoint bottomRight() {
|
||||||
return bottomRight;
|
return bottomRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.index.search.geo;
|
package org.elasticsearch.common.geo;
|
||||||
|
|
||||||
import gnu.trove.map.hash.TIntIntHashMap;
|
import gnu.trove.map.hash.TIntIntHashMap;
|
||||||
|
|
||||||
|
@ -112,10 +112,10 @@ public class GeoHashUtils {
|
||||||
return geohash.toString();
|
return geohash.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double[] decode(String geohash) {
|
public static GeoPoint decode(String geohash) {
|
||||||
double[] ret = new double[2];
|
GeoPoint point = new GeoPoint();
|
||||||
decode(geohash, ret);
|
decode(geohash, point);
|
||||||
return ret;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,7 +124,7 @@ public class GeoHashUtils {
|
||||||
* @param geohash Geohash to deocde
|
* @param geohash Geohash to deocde
|
||||||
* @return Array with the latitude at index 0, and longitude at index 1
|
* @return Array with the latitude at index 0, and longitude at index 1
|
||||||
*/
|
*/
|
||||||
public static void decode(String geohash, double[] ret) {
|
public static void decode(String geohash, GeoPoint ret) {
|
||||||
// double[] latInterval = {-90.0, 90.0};
|
// double[] latInterval = {-90.0, 90.0};
|
||||||
// double[] lngInterval = {-180.0, 180.0};
|
// double[] lngInterval = {-180.0, 180.0};
|
||||||
double latInterval0 = -90.0;
|
double latInterval0 = -90.0;
|
||||||
|
@ -160,10 +160,9 @@ public class GeoHashUtils {
|
||||||
|
|
||||||
}
|
}
|
||||||
// latitude = (latInterval[0] + latInterval[1]) / 2D;
|
// latitude = (latInterval[0] + latInterval[1]) / 2D;
|
||||||
ret[0] = (latInterval0 + latInterval1) / 2D;
|
|
||||||
// longitude = (lngInterval[0] + lngInterval[1]) / 2D;
|
// longitude = (lngInterval[0] + lngInterval[1]) / 2D;
|
||||||
ret[1] = (lngInterval0 + lngInterval1) / 2D;
|
|
||||||
|
|
||||||
|
ret.reset((latInterval0 + latInterval1) / 2D, (lngInterval0 + lngInterval1) / 2D);
|
||||||
// return ret;
|
// return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,9 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.index.mapper.geo;
|
package org.elasticsearch.common.geo;
|
||||||
|
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,6 +41,32 @@ public class GeoPoint {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GeoPoint resetLat(double lat) {
|
||||||
|
this.lat = lat;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoPoint resetLon(double lon) {
|
||||||
|
this.lon = lon;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoPoint resetFromString(String value) {
|
||||||
|
int comma = value.indexOf(',');
|
||||||
|
if (comma != -1) {
|
||||||
|
lat = Double.parseDouble(value.substring(0, comma).trim());
|
||||||
|
lon = Double.parseDouble(value.substring(comma + 1).trim());
|
||||||
|
} else {
|
||||||
|
resetFromGeoHash(value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeoPoint resetFromGeoHash(String hash) {
|
||||||
|
GeoHashUtils.decode(hash, this);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
void latlon(double lat, double lon) {
|
void latlon(double lat, double lon) {
|
||||||
this.lat = lat;
|
this.lat = lat;
|
||||||
this.lon = lon;
|
this.lon = lon;
|
||||||
|
@ -95,4 +119,8 @@ public class GeoPoint {
|
||||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "[" + lat + ", " + lon + "]";
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.index.search.geo;
|
package org.elasticsearch.common.geo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -27,7 +27,6 @@ public class GeoUtils {
|
||||||
* Normalize longitude to lie within the -180 (exclusive) to 180 (inclusive) range.
|
* Normalize longitude to lie within the -180 (exclusive) to 180 (inclusive) range.
|
||||||
*
|
*
|
||||||
* @param lon Longitude to normalize
|
* @param lon Longitude to normalize
|
||||||
* @see #normalizePoint(Point)
|
|
||||||
* @return The normalized longitude.
|
* @return The normalized longitude.
|
||||||
*/
|
*/
|
||||||
public static double normalizeLon(double lon) {
|
public static double normalizeLon(double lon) {
|
||||||
|
@ -36,16 +35,16 @@ public class GeoUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize latitude to lie within the -90 to 90 (both inclusive) range.
|
* Normalize latitude to lie within the -90 to 90 (both inclusive) range.
|
||||||
* <p>
|
* <p/>
|
||||||
* Note: You should not normalize longitude and latitude separately,
|
* Note: You should not normalize longitude and latitude separately,
|
||||||
* because when normalizing latitude it may be necessary to
|
* because when normalizing latitude it may be necessary to
|
||||||
* add a shift of 180° in the longitude.
|
* add a shift of 180° in the longitude.
|
||||||
* For this purpose, you should call the
|
* For this purpose, you should call the
|
||||||
* {@link #normalizePoint(Point)} function.
|
* {@link #normalizePoint(GeoPoint)} function.
|
||||||
*
|
*
|
||||||
* @param lat Latitude to normalize
|
* @param lat Latitude to normalize
|
||||||
* @see #normalizePoint(Point)
|
|
||||||
* @return The normalized latitude.
|
* @return The normalized latitude.
|
||||||
|
* @see #normalizePoint(GeoPoint)
|
||||||
*/
|
*/
|
||||||
public static double normalizeLat(double lat) {
|
public static double normalizeLat(double lat) {
|
||||||
lat = centeredModulus(lat, 360);
|
lat = centeredModulus(lat, 360);
|
||||||
|
@ -60,22 +59,22 @@ public class GeoUtils {
|
||||||
/**
|
/**
|
||||||
* Normalize the geo {@code Point} for its coordinates to lie within their
|
* Normalize the geo {@code Point} for its coordinates to lie within their
|
||||||
* respective normalized ranges.
|
* respective normalized ranges.
|
||||||
* <p>
|
* <p/>
|
||||||
* Note: A shift of 180° is applied in the longitude if necessary,
|
* Note: A shift of 180° is applied in the longitude if necessary,
|
||||||
* in order to normalize properly the latitude.
|
* in order to normalize properly the latitude.
|
||||||
*
|
*
|
||||||
* @param point The point to normalize in-place.
|
* @param point The point to normalize in-place.
|
||||||
*/
|
*/
|
||||||
public static void normalizePoint(Point point) {
|
public static void normalizePoint(GeoPoint point) {
|
||||||
normalizePoint(point, true, true);
|
normalizePoint(point, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize the geo {@code Point} for the given coordinates to lie within
|
* Normalize the geo {@code Point} for the given coordinates to lie within
|
||||||
* their respective normalized ranges.
|
* their respective normalized ranges.
|
||||||
*
|
* <p/>
|
||||||
* You can control which coordinate gets normalized with the two flags.
|
* You can control which coordinate gets normalized with the two flags.
|
||||||
* <p>
|
* <p/>
|
||||||
* Note: A shift of 180° is applied in the longitude if necessary,
|
* Note: A shift of 180° is applied in the longitude if necessary,
|
||||||
* in order to normalize properly the latitude.
|
* in order to normalize properly the latitude.
|
||||||
* If normalizing latitude but not longitude, it is assumed that
|
* If normalizing latitude but not longitude, it is assumed that
|
||||||
|
@ -87,32 +86,35 @@ public class GeoUtils {
|
||||||
* @param normLat Whether to normalize latitude or leave it as is.
|
* @param normLat Whether to normalize latitude or leave it as is.
|
||||||
* @param normLon Whether to normalize longitude.
|
* @param normLon Whether to normalize longitude.
|
||||||
*/
|
*/
|
||||||
public static void normalizePoint(Point point, boolean normLat, boolean normLon) {
|
public static void normalizePoint(GeoPoint point, boolean normLat, boolean normLon) {
|
||||||
|
double lat = point.lat();
|
||||||
|
double lon = point.lon();
|
||||||
if (normLat) {
|
if (normLat) {
|
||||||
point.lat = centeredModulus(point.lat, 360);
|
lat = centeredModulus(lat, 360);
|
||||||
boolean shift = true;
|
boolean shift = true;
|
||||||
if (point.lat < -90) {
|
if (lat < -90) {
|
||||||
point.lat = -180 - point.lat;
|
lat = -180 - lat;
|
||||||
} else if (point.lat > 90) {
|
} else if (lat > 90) {
|
||||||
point.lat = 180 - point.lat;
|
lat = 180 - lat;
|
||||||
} else {
|
} else {
|
||||||
// No need to shift the longitude, and the latitude is normalized
|
// No need to shift the longitude, and the latitude is normalized
|
||||||
shift = false;
|
shift = false;
|
||||||
}
|
}
|
||||||
if (shift) {
|
if (shift) {
|
||||||
if (normLon) {
|
if (normLon) {
|
||||||
point.lon += 180;
|
lon += 180;
|
||||||
} else {
|
} else {
|
||||||
// Longitude won't be normalized,
|
// Longitude won't be normalized,
|
||||||
// keep it in the form x+k*360 (with x in ]-180;180])
|
// keep it in the form x+k*360 (with x in ]-180;180])
|
||||||
// by only changing x, assuming k is meaningful for the user application.
|
// by only changing x, assuming k is meaningful for the user application.
|
||||||
point.lon += normalizeLon(point.lon) > 0 ? -180 : 180;
|
lon += normalizeLon(lon) > 0 ? -180 : 180;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (normLon) {
|
if (normLon) {
|
||||||
point.lon = centeredModulus(point.lon, 360);
|
lon = centeredModulus(lon, 360);
|
||||||
}
|
}
|
||||||
|
point.reset(lat, lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double centeredModulus(double dividend, double divisor) {
|
private static double centeredModulus(double dividend, double divisor) {
|
|
@ -20,8 +20,8 @@
|
||||||
package org.elasticsearch.index.fielddata;
|
package org.elasticsearch.index.fielddata;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticSearchIllegalStateException;
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
|
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
package org.elasticsearch.index.fielddata;
|
package org.elasticsearch.index.fielddata;
|
||||||
|
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.util.*;
|
import org.elasticsearch.index.fielddata.util.*;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.joda.time.MutableDateTime;
|
import org.joda.time.MutableDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,11 +21,11 @@ package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.FieldComparator;
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
import org.apache.lucene.search.FieldComparator;
|
import org.apache.lucene.search.FieldComparator;
|
||||||
import org.apache.lucene.search.SortField;
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@ package org.elasticsearch.index.fielddata.plain;
|
||||||
|
|
||||||
import org.apache.lucene.util.FixedBitSet;
|
import org.apache.lucene.util.FixedBitSet;
|
||||||
import org.elasticsearch.common.RamUsage;
|
import org.elasticsearch.common.RamUsage;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
|
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
|
||||||
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
|
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
|
||||||
import org.elasticsearch.index.fielddata.util.IntArrayRef;
|
import org.elasticsearch.index.fielddata.util.IntArrayRef;
|
||||||
import org.elasticsearch.index.fielddata.util.StringArrayRef;
|
import org.elasticsearch.index.fielddata.util.StringArrayRef;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.elasticsearch.index.fielddata.util;
|
package org.elasticsearch.index.fielddata.util;
|
||||||
|
|
||||||
import org.apache.lucene.util.ArrayUtil;
|
import org.apache.lucene.util.ArrayUtil;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.RandomAccess;
|
import java.util.RandomAccess;
|
||||||
|
|
|
@ -23,6 +23,9 @@ import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
|
@ -34,9 +37,6 @@ import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
|
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||||
import org.elasticsearch.index.mapper.object.ArrayValueMapperParser;
|
import org.elasticsearch.index.mapper.object.ArrayValueMapperParser;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -387,10 +387,10 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||||
|
|
||||||
private void parseLatLon(ParseContext context, double lat, double lon) throws IOException {
|
private void parseLatLon(ParseContext context, double lat, double lon) throws IOException {
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
GeoPoint point = new GeoPoint(lat, lon);
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
lat = point.lat();
|
||||||
lon = point.lon;
|
lon = point.lon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validateLat) {
|
if (validateLat) {
|
||||||
|
@ -419,38 +419,33 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseGeohash(ParseContext context, String geohash) throws IOException {
|
private void parseGeohash(ParseContext context, String geohash) throws IOException {
|
||||||
double[] values = GeoHashUtils.decode(geohash);
|
GeoPoint point = GeoHashUtils.decode(geohash);
|
||||||
double lat = values[0];
|
|
||||||
double lon = values[1];
|
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
|
||||||
lon = point.lon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validateLat) {
|
if (validateLat) {
|
||||||
if (lat > 90.0 || lat < -90.0) {
|
if (point.lat() > 90.0 || point.lat() < -90.0) {
|
||||||
throw new ElasticSearchIllegalArgumentException("illegal latitude value [" + lat + "] for " + name);
|
throw new ElasticSearchIllegalArgumentException("illegal latitude value [" + point.lat() + "] for " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (validateLon) {
|
if (validateLon) {
|
||||||
if (lon > 180.0 || lon < -180) {
|
if (point.lon() > 180.0 || point.lon() < -180) {
|
||||||
throw new ElasticSearchIllegalArgumentException("illegal longitude value [" + lon + "] for " + name);
|
throw new ElasticSearchIllegalArgumentException("illegal longitude value [" + point.lon() + "] for " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.externalValue(Double.toString(lat) + ',' + Double.toString(lon));
|
context.externalValue(Double.toString(point.lat()) + ',' + Double.toString(point.lat()));
|
||||||
geoStringMapper.parse(context);
|
geoStringMapper.parse(context);
|
||||||
if (enableGeoHash) {
|
if (enableGeoHash) {
|
||||||
context.externalValue(geohash);
|
context.externalValue(geohash);
|
||||||
geohashMapper.parse(context);
|
geohashMapper.parse(context);
|
||||||
}
|
}
|
||||||
if (enableLatLon) {
|
if (enableLatLon) {
|
||||||
context.externalValue(lat);
|
context.externalValue(point.lat());
|
||||||
latMapper.parse(context);
|
latMapper.parse(context);
|
||||||
context.externalValue(lon);
|
context.externalValue(point.lon());
|
||||||
lonMapper.parse(context);
|
lonMapper.parse(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private Point topLeft;
|
private GeoPoint topLeft;
|
||||||
|
|
||||||
private String topLeftGeohash;
|
private String topLeftGeohash;
|
||||||
|
|
||||||
private Point bottomRight;
|
private GeoPoint bottomRight;
|
||||||
|
|
||||||
private String bottomRightGeohash;
|
private String bottomRightGeohash;
|
||||||
|
|
||||||
|
@ -57,9 +57,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
* @param lon The longitude
|
* @param lon The longitude
|
||||||
*/
|
*/
|
||||||
public GeoBoundingBoxFilterBuilder topLeft(double lat, double lon) {
|
public GeoBoundingBoxFilterBuilder topLeft(double lat, double lon) {
|
||||||
topLeft = new Point();
|
topLeft = new GeoPoint(lat, lon);
|
||||||
topLeft.lat = lat;
|
|
||||||
topLeft.lon = lon;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +68,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
* @param lon The longitude
|
* @param lon The longitude
|
||||||
*/
|
*/
|
||||||
public GeoBoundingBoxFilterBuilder bottomRight(double lat, double lon) {
|
public GeoBoundingBoxFilterBuilder bottomRight(double lat, double lon) {
|
||||||
bottomRight = new Point();
|
bottomRight = new GeoPoint(lat, lon);
|
||||||
bottomRight.lat = lat;
|
|
||||||
bottomRight.lon = lon;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +120,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
if (topLeftGeohash != null) {
|
if (topLeftGeohash != null) {
|
||||||
builder.field("top_left", topLeftGeohash);
|
builder.field("top_left", topLeftGeohash);
|
||||||
} else if (topLeft != null) {
|
} else if (topLeft != null) {
|
||||||
builder.startArray("top_left").value(topLeft.lon).value(topLeft.lat).endArray();
|
builder.startArray("top_left").value(topLeft.lon()).value(topLeft.lat()).endArray();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set");
|
throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set");
|
||||||
}
|
}
|
||||||
|
@ -132,7 +128,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
if (bottomRightGeohash != null) {
|
if (bottomRightGeohash != null) {
|
||||||
builder.field("bottom_right", bottomRightGeohash);
|
builder.field("bottom_right", bottomRightGeohash);
|
||||||
} else if (bottomRight != null) {
|
} else if (bottomRight != null) {
|
||||||
builder.startArray("bottom_right").value(bottomRight.lon).value(bottomRight.lat).endArray();
|
builder.startArray("bottom_right").value(bottomRight.lon()).value(bottomRight.lat()).endArray();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryBuilderException("geo_bounding_box requires 'bottom_right' to be set");
|
throw new QueryBuilderException("geo_bounding_box requires 'bottom_right' to be set");
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
||||||
|
@ -27,7 +30,8 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.*;
|
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxFilter;
|
||||||
|
import org.elasticsearch.index.search.geo.IndexedGeoBoundingBoxFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -56,8 +60,8 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
boolean cache = false;
|
boolean cache = false;
|
||||||
CacheKeyFilter.Key cacheKey = null;
|
CacheKeyFilter.Key cacheKey = null;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
Point topLeft = new Point();
|
GeoPoint topLeft = new GeoPoint();
|
||||||
Point bottomRight = new Point();
|
GeoPoint bottomRight = new GeoPoint();
|
||||||
|
|
||||||
String filterName = null;
|
String filterName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
|
@ -76,7 +80,7 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
Point point = null;
|
GeoPoint point = null;
|
||||||
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
||||||
point = topLeft;
|
point = topLeft;
|
||||||
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
||||||
|
@ -85,15 +89,15 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
|
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
Point point = null;
|
GeoPoint point = null;
|
||||||
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
||||||
point = topLeft;
|
point = topLeft;
|
||||||
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
||||||
|
@ -106,13 +110,11 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentFieldName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentFieldName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
point.lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
point.lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
point.lat = values[0];
|
|
||||||
point.lon = values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +123,7 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
if ("field".equals(currentFieldName)) {
|
if ("field".equals(currentFieldName)) {
|
||||||
fieldName = parser.text();
|
fieldName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
Point point = null;
|
GeoPoint point = null;
|
||||||
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
if ("top_left".equals(currentFieldName) || "topLeft".equals(currentFieldName)) {
|
||||||
point = topLeft;
|
point = topLeft;
|
||||||
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
} else if ("bottom_right".equals(currentFieldName) || "bottomRight".equals(currentFieldName)) {
|
||||||
|
@ -130,15 +132,7 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
|
||||||
|
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
String value = parser.text();
|
String value = parser.text();
|
||||||
int comma = value.indexOf(',');
|
point.resetFromString(value);
|
||||||
if (comma != -1) {
|
|
||||||
point.lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
point.lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
point.lat = values[0];
|
|
||||||
point.lon = values[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -28,7 +32,7 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.*;
|
import org.elasticsearch.index.search.geo.GeoDistanceFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -65,8 +69,7 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
CacheKeyFilter.Key cacheKey = null;
|
CacheKeyFilter.Key cacheKey = null;
|
||||||
String filterName = null;
|
String filterName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
double lat = 0;
|
GeoPoint point = new GeoPoint();
|
||||||
double lon = 0;
|
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
double distance = 0;
|
double distance = 0;
|
||||||
Object vDistance = null;
|
Object vDistance = null;
|
||||||
|
@ -80,9 +83,9 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,13 +99,11 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
} else {
|
} else {
|
||||||
throw new QueryParsingException(parseContext.index(), "[geo_distance] filter does not support [" + currentFieldName + "]");
|
throw new QueryParsingException(parseContext.index(), "[geo_distance] filter does not support [" + currentFieldName + "]");
|
||||||
}
|
}
|
||||||
|
@ -120,15 +121,13 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
} else if (currentFieldName.equals("distance_type") || currentFieldName.equals("distanceType")) {
|
} else if (currentFieldName.equals("distance_type") || currentFieldName.equals("distanceType")) {
|
||||||
geoDistance = GeoDistance.fromString(parser.text());
|
geoDistance = GeoDistance.fromString(parser.text());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LAT_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LAT_SUFFIX)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LAT_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LAT_SUFFIX.length());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LON_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LON_SUFFIX)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LON_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LON_SUFFIX.length());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.GEOHASH_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.GEOHASH_SUFFIX)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
filterName = parser.text();
|
filterName = parser.text();
|
||||||
|
@ -142,17 +141,7 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
normalizeLat = parser.booleanValue();
|
normalizeLat = parser.booleanValue();
|
||||||
normalizeLon = parser.booleanValue();
|
normalizeLon = parser.booleanValue();
|
||||||
} else {
|
} else {
|
||||||
// assume the value is the actual value
|
point.resetFromString(parser.text());
|
||||||
String value = parser.text();
|
|
||||||
int comma = value.indexOf(',');
|
|
||||||
if (comma != -1) {
|
|
||||||
lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +155,7 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
distance = geoDistance.normalize(distance, DistanceUnit.MILES);
|
distance = geoDistance.normalize(distance, DistanceUnit.MILES);
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
|
||||||
lon = point.lon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
|
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
|
||||||
|
@ -184,7 +170,7 @@ public class GeoDistanceFilterParser implements FilterParser {
|
||||||
|
|
||||||
|
|
||||||
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
||||||
Filter filter = new GeoDistanceFilter(lat, lon, distance, geoDistance, indexFieldData, geoMapper, optimizeBbox);
|
Filter filter = new GeoDistanceFilter(point.lat(), point.lon(), distance, geoDistance, indexFieldData, geoMapper, optimizeBbox);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
filter = parseContext.cacheFilter(filter, cacheKey);
|
filter = parseContext.cacheFilter(filter, cacheKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -28,7 +32,7 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.*;
|
import org.elasticsearch.index.search.geo.GeoDistanceRangeFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -65,8 +69,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
CacheKeyFilter.Key cacheKey = null;
|
CacheKeyFilter.Key cacheKey = null;
|
||||||
String filterName = null;
|
String filterName = null;
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
double lat = 0;
|
GeoPoint point = new GeoPoint();
|
||||||
double lon = 0;
|
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
Object vFrom = null;
|
Object vFrom = null;
|
||||||
Object vTo = null;
|
Object vTo = null;
|
||||||
|
@ -82,12 +85,13 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
double lon = parser.doubleValue();
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lat = parser.doubleValue();
|
double lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
point.reset(lat, lon);
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
// the json in the format of -> field : { lat : 30, lon : 12 }
|
// the json in the format of -> field : { lat : 30, lon : 12 }
|
||||||
|
@ -98,13 +102,11 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,15 +166,13 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
} else if (currentFieldName.equals("distance_type") || currentFieldName.equals("distanceType")) {
|
} else if (currentFieldName.equals("distance_type") || currentFieldName.equals("distanceType")) {
|
||||||
geoDistance = GeoDistance.fromString(parser.text());
|
geoDistance = GeoDistance.fromString(parser.text());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LAT_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LAT_SUFFIX)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LAT_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LAT_SUFFIX.length());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LON_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.LON_SUFFIX)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LON_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.LON_SUFFIX.length());
|
||||||
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.GEOHASH_SUFFIX)) {
|
} else if (currentFieldName.endsWith(GeoPointFieldMapper.Names.GEOHASH_SUFFIX)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
fieldName = currentFieldName.substring(0, currentFieldName.length() - GeoPointFieldMapper.Names.GEOHASH_SUFFIX.length());
|
||||||
} else if ("_name".equals(currentFieldName)) {
|
} else if ("_name".equals(currentFieldName)) {
|
||||||
filterName = parser.text();
|
filterName = parser.text();
|
||||||
|
@ -186,17 +186,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
normalizeLat = parser.booleanValue();
|
normalizeLat = parser.booleanValue();
|
||||||
normalizeLon = parser.booleanValue();
|
normalizeLon = parser.booleanValue();
|
||||||
} else {
|
} else {
|
||||||
// assume the value is the actual value
|
point.resetFromString(parser.text());
|
||||||
String value = parser.text();
|
|
||||||
int comma = value.indexOf(',');
|
|
||||||
if (comma != -1) {
|
|
||||||
lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,10 +212,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
|
||||||
lon = point.lon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
|
MapperService.SmartNameFieldMappers smartMappers = parseContext.smartFieldMappers(fieldName);
|
||||||
|
@ -239,7 +226,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||||
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper.GeoStringFieldMapper) mapper).geoMapper();
|
GeoPointFieldMapper geoMapper = ((GeoPointFieldMapper.GeoStringFieldMapper) mapper).geoMapper();
|
||||||
|
|
||||||
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
||||||
Filter filter = new GeoDistanceRangeFilter(lat, lon, from, to, includeLower, includeUpper, geoDistance, geoMapper, indexFieldData, optimizeBbox);
|
Filter filter = new GeoDistanceRangeFilter(point, from, to, includeLower, includeUpper, geoDistance, geoMapper, indexFieldData, optimizeBbox);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
filter = parseContext.cacheFilter(filter, cacheKey);
|
filter = parseContext.cacheFilter(filter, cacheKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -34,7 +34,7 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final List<Point> points = Lists.newArrayList();
|
private final List<GeoPoint> points = Lists.newArrayList();
|
||||||
|
|
||||||
private Boolean cache;
|
private Boolean cache;
|
||||||
private String cacheKey;
|
private String cacheKey;
|
||||||
|
@ -53,13 +53,13 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public GeoPolygonFilterBuilder addPoint(double lat, double lon) {
|
public GeoPolygonFilterBuilder addPoint(double lat, double lon) {
|
||||||
points.add(new Point(lat, lon));
|
points.add(new GeoPoint(lat, lon));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoPolygonFilterBuilder addPoint(String geohash) {
|
public GeoPolygonFilterBuilder addPoint(String geohash) {
|
||||||
double[] values = GeoHashUtils.decode(geohash);
|
points.add(GeoHashUtils.decode(geohash));
|
||||||
return addPoint(values[0], values[1]);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,8 +89,8 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
||||||
|
|
||||||
builder.startObject(name);
|
builder.startObject(name);
|
||||||
builder.startArray("points");
|
builder.startArray("points");
|
||||||
for (Point point : points) {
|
for (GeoPoint point : points) {
|
||||||
builder.startArray().value(point.lon).value(point.lat).endArray();
|
builder.startArray().value(point.lon()).value(point.lat()).endArray();
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -21,6 +21,9 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
||||||
|
@ -28,10 +31,7 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoPolygonFilter;
|
import org.elasticsearch.index.search.geo.GeoPolygonFilter;
|
||||||
import org.elasticsearch.index.search.geo.GeoUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -70,7 +70,7 @@ public class GeoPolygonFilterParser implements FilterParser {
|
||||||
boolean cache = false;
|
boolean cache = false;
|
||||||
CacheKeyFilter.Key cacheKey = null;
|
CacheKeyFilter.Key cacheKey = null;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
List<Point> points = Lists.newArrayList();
|
List<GeoPoint> points = Lists.newArrayList();
|
||||||
|
|
||||||
boolean normalizeLon = true;
|
boolean normalizeLon = true;
|
||||||
boolean normalizeLat = true;
|
boolean normalizeLat = true;
|
||||||
|
@ -94,46 +94,32 @@ public class GeoPolygonFilterParser implements FilterParser {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
Point point = new Point();
|
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lon = parser.doubleValue();
|
double lon = parser.doubleValue();
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lat = parser.doubleValue();
|
double lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
points.add(point);
|
points.add(new GeoPoint(lat, lon));
|
||||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||||
Point point = new Point();
|
GeoPoint point = new GeoPoint();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentFieldName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentFieldName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
point.lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
point.lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentFieldName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
point.lat = values[0];
|
|
||||||
point.lon = values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
points.add(point);
|
points.add(point);
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
Point point = new Point();
|
points.add(new GeoPoint().resetFromString(parser.text()));
|
||||||
String value = parser.text();
|
|
||||||
int comma = value.indexOf(',');
|
|
||||||
if (comma != -1) {
|
|
||||||
point.lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
point.lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
point.lat = values[0];
|
|
||||||
point.lon = values[1];
|
|
||||||
}
|
|
||||||
points.add(point);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,7 +148,7 @@ public class GeoPolygonFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
for (Point point : points) {
|
for (GeoPoint point : points) {
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +163,7 @@ public class GeoPolygonFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
IndexGeoPointFieldData indexFieldData = parseContext.fieldData().getForField(mapper);
|
||||||
Filter filter = new GeoPolygonFilter(points.toArray(new Point[points.size()]), indexFieldData);
|
Filter filter = new GeoPolygonFilter(points.toArray(new GeoPoint[points.size()]), indexFieldData);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
filter = parseContext.cacheFilter(filter, cacheKey);
|
filter = parseContext.cacheFilter(filter, cacheKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,14 @@ import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.lucene.docset.AndDocIdSet;
|
import org.elasticsearch.common.lucene.docset.AndDocIdSet;
|
||||||
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
||||||
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -26,13 +26,14 @@ import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.NumericUtils;
|
import org.apache.lucene.util.NumericUtils;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.lucene.docset.AndDocIdSet;
|
import org.elasticsearch.common.lucene.docset.AndDocIdSet;
|
||||||
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
||||||
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -55,10 +56,10 @@ public class GeoDistanceRangeFilter extends Filter {
|
||||||
|
|
||||||
private final IndexGeoPointFieldData indexFieldData;
|
private final IndexGeoPointFieldData indexFieldData;
|
||||||
|
|
||||||
public GeoDistanceRangeFilter(double lat, double lon, Double lowerVal, Double upperVal, boolean includeLower, boolean includeUpper, GeoDistance geoDistance, GeoPointFieldMapper mapper, IndexGeoPointFieldData indexFieldData,
|
public GeoDistanceRangeFilter(GeoPoint point, Double lowerVal, Double upperVal, boolean includeLower, boolean includeUpper, GeoDistance geoDistance, GeoPointFieldMapper mapper, IndexGeoPointFieldData indexFieldData,
|
||||||
String optimizeBbox) {
|
String optimizeBbox) {
|
||||||
this.lat = lat;
|
this.lat = point.lat();
|
||||||
this.lon = lon;
|
this.lon = point.lon();
|
||||||
this.geoDistance = geoDistance;
|
this.geoDistance = geoDistance;
|
||||||
this.indexFieldData = indexFieldData;
|
this.indexFieldData = indexFieldData;
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -37,16 +37,16 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public class GeoPolygonFilter extends Filter {
|
public class GeoPolygonFilter extends Filter {
|
||||||
|
|
||||||
private final Point[] points;
|
private final GeoPoint[] points;
|
||||||
|
|
||||||
private final IndexGeoPointFieldData indexFieldData;
|
private final IndexGeoPointFieldData indexFieldData;
|
||||||
|
|
||||||
public GeoPolygonFilter(Point[] points, IndexGeoPointFieldData indexFieldData) {
|
public GeoPolygonFilter(GeoPoint[] points, IndexGeoPointFieldData indexFieldData) {
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.indexFieldData = indexFieldData;
|
this.indexFieldData = indexFieldData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point[] points() {
|
public GeoPoint[] points() {
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ public class GeoPolygonFilter extends Filter {
|
||||||
|
|
||||||
public static class GeoPolygonDocIdSet extends MatchDocIdSet {
|
public static class GeoPolygonDocIdSet extends MatchDocIdSet {
|
||||||
private final GeoPointValues values;
|
private final GeoPointValues values;
|
||||||
private final Point[] points;
|
private final GeoPoint[] points;
|
||||||
|
|
||||||
public GeoPolygonDocIdSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, Point[] points) {
|
public GeoPolygonDocIdSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, GeoPoint[] points) {
|
||||||
super(maxDoc, acceptDocs);
|
super(maxDoc, acceptDocs);
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
|
@ -101,16 +101,16 @@ public class GeoPolygonFilter extends Filter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean pointInPolygon(Point[] points, double lat, double lon) {
|
private static boolean pointInPolygon(GeoPoint[] points, double lat, double lon) {
|
||||||
int i;
|
int i;
|
||||||
int j = points.length - 1;
|
int j = points.length - 1;
|
||||||
boolean inPoly = false;
|
boolean inPoly = false;
|
||||||
|
|
||||||
for (i = 0; i < points.length; i++) {
|
for (i = 0; i < points.length; i++) {
|
||||||
if (points[i].lon < lon && points[j].lon >= lon
|
if (points[i].lon() < lon && points[j].lon() >= lon
|
||||||
|| points[j].lon < lon && points[i].lon >= lon) {
|
|| points[j].lon() < lon && points[i].lon() >= lon) {
|
||||||
if (points[i].lat + (lon - points[i].lon) /
|
if (points[i].lat() + (lon - points[i].lon()) /
|
||||||
(points[j].lon - points[i].lon) * (points[j].lat - points[i].lat) < lat) {
|
(points[j].lon() - points[i].lon()) * (points[j].lat() - points[i].lat()) < lat) {
|
||||||
inPoly = !inPoly;
|
inPoly = !inPoly;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@ import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPoint;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -36,22 +36,22 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class InMemoryGeoBoundingBoxFilter extends Filter {
|
public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
|
|
||||||
private final Point topLeft;
|
private final GeoPoint topLeft;
|
||||||
private final Point bottomRight;
|
private final GeoPoint bottomRight;
|
||||||
|
|
||||||
private final IndexGeoPointFieldData indexFieldData;
|
private final IndexGeoPointFieldData indexFieldData;
|
||||||
|
|
||||||
public InMemoryGeoBoundingBoxFilter(Point topLeft, Point bottomRight, IndexGeoPointFieldData indexFieldData) {
|
public InMemoryGeoBoundingBoxFilter(GeoPoint topLeft, GeoPoint bottomRight, IndexGeoPointFieldData indexFieldData) {
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
this.bottomRight = bottomRight;
|
this.bottomRight = bottomRight;
|
||||||
this.indexFieldData = indexFieldData;
|
this.indexFieldData = indexFieldData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point topLeft() {
|
public GeoPoint topLeft() {
|
||||||
return topLeft;
|
return topLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point bottomRight() {
|
public GeoPoint bottomRight() {
|
||||||
return bottomRight;
|
return bottomRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
final GeoPointValues values = indexFieldData.load(context).getGeoPointValues();
|
final GeoPointValues values = indexFieldData.load(context).getGeoPointValues();
|
||||||
|
|
||||||
//checks to see if bounding box crosses 180 degrees
|
//checks to see if bounding box crosses 180 degrees
|
||||||
if (topLeft.lon > bottomRight.lon) {
|
if (topLeft.lon() > bottomRight.lon()) {
|
||||||
return new Meridian180GeoBoundingBoxDocSet(context.reader().maxDoc(), acceptedDocs, values, topLeft, bottomRight);
|
return new Meridian180GeoBoundingBoxDocSet(context.reader().maxDoc(), acceptedDocs, values, topLeft, bottomRight);
|
||||||
} else {
|
} else {
|
||||||
return new GeoBoundingBoxDocSet(context.reader().maxDoc(), acceptedDocs, values, topLeft, bottomRight);
|
return new GeoBoundingBoxDocSet(context.reader().maxDoc(), acceptedDocs, values, topLeft, bottomRight);
|
||||||
|
@ -78,10 +78,10 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
|
|
||||||
public static class Meridian180GeoBoundingBoxDocSet extends MatchDocIdSet {
|
public static class Meridian180GeoBoundingBoxDocSet extends MatchDocIdSet {
|
||||||
private final GeoPointValues values;
|
private final GeoPointValues values;
|
||||||
private final Point topLeft;
|
private final GeoPoint topLeft;
|
||||||
private final Point bottomRight;
|
private final GeoPoint bottomRight;
|
||||||
|
|
||||||
public Meridian180GeoBoundingBoxDocSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, Point topLeft, Point bottomRight) {
|
public Meridian180GeoBoundingBoxDocSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, GeoPoint topLeft, GeoPoint bottomRight) {
|
||||||
super(maxDoc, acceptDocs);
|
super(maxDoc, acceptDocs);
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
|
@ -103,16 +103,16 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
GeoPointValues.Iter iter = values.getIter(doc);
|
GeoPointValues.Iter iter = values.getIter(doc);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
GeoPoint point = iter.next();
|
GeoPoint point = iter.next();
|
||||||
if (((topLeft.lon <= point.lon() || bottomRight.lon >= point.lon())) &&
|
if (((topLeft.lon() <= point.lon() || bottomRight.lon() >= point.lon())) &&
|
||||||
(topLeft.lat >= point.lat() && bottomRight.lat <= point.lat())) {
|
(topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GeoPoint point = values.getValue(doc);
|
GeoPoint point = values.getValue(doc);
|
||||||
|
|
||||||
if (((topLeft.lon <= point.lon() || bottomRight.lon >= point.lon())) &&
|
if (((topLeft.lon() <= point.lon() || bottomRight.lon() >= point.lon())) &&
|
||||||
(topLeft.lat >= point.lat() && bottomRight.lat <= point.lat())) {
|
(topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,10 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
|
|
||||||
public static class GeoBoundingBoxDocSet extends MatchDocIdSet {
|
public static class GeoBoundingBoxDocSet extends MatchDocIdSet {
|
||||||
private final GeoPointValues values;
|
private final GeoPointValues values;
|
||||||
private final Point topLeft;
|
private final GeoPoint topLeft;
|
||||||
private final Point bottomRight;
|
private final GeoPoint bottomRight;
|
||||||
|
|
||||||
public GeoBoundingBoxDocSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, Point topLeft, Point bottomRight) {
|
public GeoBoundingBoxDocSet(int maxDoc, @Nullable Bits acceptDocs, GeoPointValues values, GeoPoint topLeft, GeoPoint bottomRight) {
|
||||||
super(maxDoc, acceptDocs);
|
super(maxDoc, acceptDocs);
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
|
@ -147,15 +147,15 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
|
||||||
GeoPointValues.Iter iter = values.getIter(doc);
|
GeoPointValues.Iter iter = values.getIter(doc);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
GeoPoint point = iter.next();
|
GeoPoint point = iter.next();
|
||||||
if (topLeft.lon <= point.lon() && bottomRight.lon >= point.lon()
|
if (topLeft.lon() <= point.lon() && bottomRight.lon() >= point.lon()
|
||||||
&& topLeft.lat >= point.lat() && bottomRight.lat <= point.lat()) {
|
&& topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GeoPoint point = values.getValue(doc);
|
GeoPoint point = values.getValue(doc);
|
||||||
if (topLeft.lon <= point.lon() && bottomRight.lon >= point.lon()
|
if (topLeft.lon() <= point.lon() && bottomRight.lon() >= point.lon()
|
||||||
&& topLeft.lat >= point.lat() && bottomRight.lat <= point.lat()) {
|
&& topLeft.lat() >= point.lat() && bottomRight.lat() <= point.lat()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.FixedBitSet;
|
import org.apache.lucene.util.FixedBitSet;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
|
|
||||||
|
@ -34,12 +35,12 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class IndexedGeoBoundingBoxFilter {
|
public class IndexedGeoBoundingBoxFilter {
|
||||||
|
|
||||||
public static Filter create(Point topLeft, Point bottomRight, GeoPointFieldMapper fieldMapper) {
|
public static Filter create(GeoPoint topLeft, GeoPoint bottomRight, GeoPointFieldMapper fieldMapper) {
|
||||||
if (!fieldMapper.isEnableLatLon()) {
|
if (!fieldMapper.isEnableLatLon()) {
|
||||||
throw new ElasticSearchIllegalArgumentException("lat/lon is not enabled (indexed) for field [" + fieldMapper.name() + "], can't use indexed filter on it");
|
throw new ElasticSearchIllegalArgumentException("lat/lon is not enabled (indexed) for field [" + fieldMapper.name() + "], can't use indexed filter on it");
|
||||||
}
|
}
|
||||||
//checks to see if bounding box crosses 180 degrees
|
//checks to see if bounding box crosses 180 degrees
|
||||||
if (topLeft.lon > bottomRight.lon) {
|
if (topLeft.lon() > bottomRight.lon()) {
|
||||||
return new LeftGeoBoundingBoxFilter(topLeft, bottomRight, fieldMapper);
|
return new LeftGeoBoundingBoxFilter(topLeft, bottomRight, fieldMapper);
|
||||||
} else {
|
} else {
|
||||||
return new RightGeoBoundingBoxFilter(topLeft, bottomRight, fieldMapper);
|
return new RightGeoBoundingBoxFilter(topLeft, bottomRight, fieldMapper);
|
||||||
|
@ -52,10 +53,10 @@ public class IndexedGeoBoundingBoxFilter {
|
||||||
final Filter lonFilter2;
|
final Filter lonFilter2;
|
||||||
final Filter latFilter;
|
final Filter latFilter;
|
||||||
|
|
||||||
public LeftGeoBoundingBoxFilter(Point topLeft, Point bottomRight, GeoPointFieldMapper fieldMapper) {
|
public LeftGeoBoundingBoxFilter(GeoPoint topLeft, GeoPoint bottomRight, GeoPointFieldMapper fieldMapper) {
|
||||||
lonFilter1 = fieldMapper.lonMapper().rangeFilter(null, bottomRight.lon, true, true);
|
lonFilter1 = fieldMapper.lonMapper().rangeFilter(null, bottomRight.lon(), true, true);
|
||||||
lonFilter2 = fieldMapper.lonMapper().rangeFilter(topLeft.lon, null, true, true);
|
lonFilter2 = fieldMapper.lonMapper().rangeFilter(topLeft.lon(), null, true, true);
|
||||||
latFilter = fieldMapper.latMapper().rangeFilter(bottomRight.lat, topLeft.lat, true, true);
|
latFilter = fieldMapper.latMapper().rangeFilter(bottomRight.lat(), topLeft.lat(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,9 +120,9 @@ public class IndexedGeoBoundingBoxFilter {
|
||||||
final Filter lonFilter;
|
final Filter lonFilter;
|
||||||
final Filter latFilter;
|
final Filter latFilter;
|
||||||
|
|
||||||
public RightGeoBoundingBoxFilter(Point topLeft, Point bottomRight, GeoPointFieldMapper fieldMapper) {
|
public RightGeoBoundingBoxFilter(GeoPoint topLeft, GeoPoint bottomRight, GeoPointFieldMapper fieldMapper) {
|
||||||
lonFilter = fieldMapper.lonMapper().rangeFilter(topLeft.lon, bottomRight.lon, true, true);
|
lonFilter = fieldMapper.lonMapper().rangeFilter(topLeft.lon(), bottomRight.lon(), true, true);
|
||||||
latFilter = fieldMapper.latMapper().rangeFilter(bottomRight.lat, topLeft.lat, true, true);
|
latFilter = fieldMapper.latMapper().rangeFilter(bottomRight.lat(), topLeft.lat(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to ElasticSearch and Shay Banon under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. ElasticSearch licenses this
|
|
||||||
* file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.elasticsearch.index.search.geo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class Point {
|
|
||||||
public double lat;
|
|
||||||
public double lon;
|
|
||||||
|
|
||||||
public Point() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point(double lat, double lon) {
|
|
||||||
this.lat = lat;
|
|
||||||
this.lon = lon;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
Point point = (Point) o;
|
|
||||||
|
|
||||||
if (Double.compare(point.lat, lat) != 0) return false;
|
|
||||||
if (Double.compare(point.lon, lon) != 0) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result;
|
|
||||||
long temp;
|
|
||||||
temp = lat != +0.0d ? Double.doubleToLongBits(lat) : 0L;
|
|
||||||
result = (int) (temp ^ (temp >>> 32));
|
|
||||||
temp = lon != +0.0d ? Double.doubleToLongBits(lon) : 0L;
|
|
||||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "[" + lat + ", " + lon + "]";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.search.facet.geodistance;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.query.FilterBuilder;
|
import org.elasticsearch.index.query.FilterBuilder;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilderException;
|
import org.elasticsearch.search.builder.SearchSourceBuilderException;
|
||||||
import org.elasticsearch.search.facet.AbstractFacetBuilder;
|
import org.elasticsearch.search.facet.AbstractFacetBuilder;
|
||||||
|
|
||||||
|
@ -36,8 +36,6 @@ import java.util.Map;
|
||||||
* A geo distance builder allowing to create a facet of distances from a specific location including the
|
* A geo distance builder allowing to create a facet of distances from a specific location including the
|
||||||
* number of hits within each distance range, and aggregated data (like totals of either the distance or
|
* number of hits within each distance range, and aggregated data (like totals of either the distance or
|
||||||
* cusotm value fields).
|
* cusotm value fields).
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class GeoDistanceFacetBuilder extends AbstractFacetBuilder {
|
public class GeoDistanceFacetBuilder extends AbstractFacetBuilder {
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
package org.elasticsearch.search.facet.geodistance;
|
package org.elasticsearch.search.facet.geodistance;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.search.facet.AbstractFacetCollector;
|
import org.elasticsearch.search.facet.AbstractFacetCollector;
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
|
@ -21,6 +21,10 @@ package org.elasticsearch.search.facet.geodistance;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
import org.elasticsearch.common.component.AbstractComponent;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
|
@ -29,10 +33,6 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
import org.elasticsearch.search.facet.Facet;
|
import org.elasticsearch.search.facet.Facet;
|
||||||
import org.elasticsearch.search.facet.FacetCollector;
|
import org.elasticsearch.search.facet.FacetCollector;
|
||||||
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
import org.elasticsearch.search.facet.FacetPhaseExecutionException;
|
||||||
|
@ -66,8 +66,7 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
String valueScript = null;
|
String valueScript = null;
|
||||||
String scriptLang = null;
|
String scriptLang = null;
|
||||||
Map<String, Object> params = null;
|
Map<String, Object> params = null;
|
||||||
double lat = Double.NaN;
|
GeoPoint point = new GeoPoint();
|
||||||
double lon = Double.NaN;
|
|
||||||
DistanceUnit unit = DistanceUnit.KILOMETERS;
|
DistanceUnit unit = DistanceUnit.KILOMETERS;
|
||||||
GeoDistance geoDistance = GeoDistance.ARC;
|
GeoDistance geoDistance = GeoDistance.ARC;
|
||||||
List<GeoDistanceFacet.Entry> entries = Lists.newArrayList();
|
List<GeoDistanceFacet.Entry> entries = Lists.newArrayList();
|
||||||
|
@ -105,9 +104,9 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,13 +123,11 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,35 +148,19 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
normalizeLon = parser.booleanValue();
|
normalizeLon = parser.booleanValue();
|
||||||
} else {
|
} else {
|
||||||
// assume the value is the actual value
|
// assume the value is the actual value
|
||||||
String value = parser.text();
|
point.resetFromString(parser.text());
|
||||||
int comma = value.indexOf(',');
|
|
||||||
if (comma != -1) {
|
|
||||||
lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldName = currentName;
|
fieldName = currentName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Double.isNaN(lat) || Double.isNaN(lon)) {
|
|
||||||
throw new FacetPhaseExecutionException(facetName, "lat/lon not set for geo_distance facet");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
throw new FacetPhaseExecutionException(facetName, "no ranges defined for geo_distance facet");
|
throw new FacetPhaseExecutionException(facetName, "no ranges defined for geo_distance facet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
|
||||||
lon = point.lon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapper keyFieldMapper = context.smartNameFieldMapper(fieldName);
|
FieldMapper keyFieldMapper = context.smartNameFieldMapper(fieldName);
|
||||||
|
@ -194,16 +175,16 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
throw new FacetPhaseExecutionException(facetName, "failed to find mapping for [" + valueFieldName + "]");
|
throw new FacetPhaseExecutionException(facetName, "failed to find mapping for [" + valueFieldName + "]");
|
||||||
}
|
}
|
||||||
IndexNumericFieldData valueIndexFieldData = context.fieldData().getForField(valueFieldMapper);
|
IndexNumericFieldData valueIndexFieldData = context.fieldData().getForField(valueFieldMapper);
|
||||||
return new ValueGeoDistanceFacetCollector(facetName, keyIndexFieldData, lat, lon, unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
return new ValueGeoDistanceFacetCollector(facetName, keyIndexFieldData, point.lat(), point.lon(), unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
||||||
context, valueIndexFieldData);
|
context, valueIndexFieldData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueScript != null) {
|
if (valueScript != null) {
|
||||||
return new ScriptGeoDistanceFacetCollector(facetName, keyIndexFieldData, lat, lon, unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
return new ScriptGeoDistanceFacetCollector(facetName, keyIndexFieldData, point.lat(), point.lon(), unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
||||||
context, scriptLang, valueScript, params);
|
context, scriptLang, valueScript, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GeoDistanceFacetCollector(facetName, keyIndexFieldData, lat, lon, unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
return new GeoDistanceFacetCollector(facetName, keyIndexFieldData, point.lat(), point.lon(), unit, geoDistance, entries.toArray(new GeoDistanceFacet.Entry[entries.size()]),
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.elasticsearch.search.facet.geodistance;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.script.SearchScript;
|
import org.elasticsearch.script.SearchScript;
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
package org.elasticsearch.search.facet.geodistance;
|
package org.elasticsearch.search.facet.geodistance;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.fielddata.DoubleValues;
|
import org.elasticsearch.index.fielddata.DoubleValues;
|
||||||
import org.elasticsearch.index.fielddata.GeoPointValues;
|
import org.elasticsearch.index.fielddata.GeoPointValues;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -19,16 +19,14 @@
|
||||||
|
|
||||||
package org.elasticsearch.search.sort;
|
package org.elasticsearch.search.sort;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A geo distance based sorting on a geo point like field.
|
* A geo distance based sorting on a geo point like field.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class GeoDistanceSortBuilder extends SortBuilder {
|
public class GeoDistanceSortBuilder extends SortBuilder {
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,16 @@ package org.elasticsearch.search.sort;
|
||||||
|
|
||||||
import org.apache.lucene.search.SortField;
|
import org.apache.lucene.search.SortField;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.GeoDistanceComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.GeoDistanceComparatorSource;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.GeoUtils;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,8 +46,7 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
@Override
|
@Override
|
||||||
public SortField parse(XContentParser parser, SearchContext context) throws Exception {
|
public SortField parse(XContentParser parser, SearchContext context) throws Exception {
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
double lat = Double.NaN;
|
GeoPoint point = new GeoPoint();
|
||||||
double lon = Double.NaN;
|
|
||||||
DistanceUnit unit = DistanceUnit.KILOMETERS;
|
DistanceUnit unit = DistanceUnit.KILOMETERS;
|
||||||
GeoDistance geoDistance = GeoDistance.ARC;
|
GeoDistance geoDistance = GeoDistance.ARC;
|
||||||
boolean reverse = false;
|
boolean reverse = false;
|
||||||
|
@ -62,9 +61,9 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,13 +76,11 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
if (currentName.equals(GeoPointFieldMapper.Names.LAT)) {
|
||||||
lat = parser.doubleValue();
|
point.resetLat(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.LON)) {
|
||||||
lon = parser.doubleValue();
|
point.resetLon(parser.doubleValue());
|
||||||
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
} else if (currentName.equals(GeoPointFieldMapper.Names.GEOHASH)) {
|
||||||
double[] values = GeoHashUtils.decode(parser.text());
|
GeoHashUtils.decode(parser.text(), point);
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,28 +97,14 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
normalizeLat = parser.booleanValue();
|
normalizeLat = parser.booleanValue();
|
||||||
normalizeLon = parser.booleanValue();
|
normalizeLon = parser.booleanValue();
|
||||||
} else {
|
} else {
|
||||||
// assume the value is the actual value
|
point.resetFromString(parser.text());
|
||||||
String value = parser.text();
|
|
||||||
int comma = value.indexOf(',');
|
|
||||||
if (comma != -1) {
|
|
||||||
lat = Double.parseDouble(value.substring(0, comma).trim());
|
|
||||||
lon = Double.parseDouble(value.substring(comma + 1).trim());
|
|
||||||
} else {
|
|
||||||
double[] values = GeoHashUtils.decode(value);
|
|
||||||
lat = values[0];
|
|
||||||
lon = values[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldName = currentName;
|
fieldName = currentName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normalizeLat || normalizeLon) {
|
if (normalizeLat || normalizeLon) {
|
||||||
Point point = new Point(lat, lon);
|
|
||||||
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
GeoUtils.normalizePoint(point, normalizeLat, normalizeLon);
|
||||||
lat = point.lat;
|
|
||||||
lon = point.lon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapper mapper = context.smartNameFieldMapper(fieldName);
|
FieldMapper mapper = context.smartNameFieldMapper(fieldName);
|
||||||
|
@ -130,6 +113,6 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
}
|
}
|
||||||
IndexGeoPointFieldData indexFieldData = context.fieldData().getForField(mapper);
|
IndexGeoPointFieldData indexFieldData = context.fieldData().getForField(mapper);
|
||||||
|
|
||||||
return new SortField(fieldName, new GeoDistanceComparatorSource(indexFieldData, lat, lon, unit, geoDistance), reverse);
|
return new SortField(fieldName, new GeoDistanceComparatorSource(indexFieldData, point.lat(), point.lon(), unit, geoDistance), reverse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,11 @@ package org.elasticsearch.benchmark.search.geo;
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.unit.SizeValue;
|
import org.elasticsearch.common.unit.SizeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.node.Node;
|
import org.elasticsearch.node.Node;
|
||||||
import org.elasticsearch.node.NodeBuilder;
|
import org.elasticsearch.node.NodeBuilder;
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ package org.elasticsearch.test.integration.search.geo;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.search.sort.SortBuilders;
|
import org.elasticsearch.search.sort.SortBuilders;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
|
|
@ -21,13 +21,13 @@ package org.elasticsearch.test.integration.validate;
|
||||||
|
|
||||||
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
|
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.FilterBuilders;
|
import org.elasticsearch.index.query.FilterBuilders;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.test.integration.AbstractNodesTests;
|
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.mapper.geo;
|
package org.elasticsearch.test.unit.index.mapper.geo;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||||
import org.hamcrest.MatcherAssert;
|
import org.hamcrest.MatcherAssert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.mapper.geo;
|
package org.elasticsearch.test.unit.index.mapper.geo;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.mapper.geo;
|
package org.elasticsearch.test.unit.index.mapper.geo;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
|
|
@ -1803,10 +1803,10 @@ public class SimpleIndexQueryParserTests {
|
||||||
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery.query();
|
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery.query();
|
||||||
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.topLeft().lat, closeTo(40, 0.00001));
|
assertThat(filter.topLeft().lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.topLeft().lon, closeTo(-70, 0.00001));
|
assertThat(filter.topLeft().lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.bottomRight().lat, closeTo(30, 0.00001));
|
assertThat(filter.bottomRight().lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.bottomRight().lon, closeTo(-80, 0.00001));
|
assertThat(filter.bottomRight().lon(), closeTo(-80, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1819,10 +1819,10 @@ public class SimpleIndexQueryParserTests {
|
||||||
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
||||||
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.topLeft().lat, closeTo(40, 0.00001));
|
assertThat(filter.topLeft().lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.topLeft().lon, closeTo(-70, 0.00001));
|
assertThat(filter.topLeft().lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.bottomRight().lat, closeTo(30, 0.00001));
|
assertThat(filter.bottomRight().lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.bottomRight().lon, closeTo(-80, 0.00001));
|
assertThat(filter.bottomRight().lon(), closeTo(-80, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1834,10 +1834,10 @@ public class SimpleIndexQueryParserTests {
|
||||||
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
||||||
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.topLeft().lat, closeTo(40, 0.00001));
|
assertThat(filter.topLeft().lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.topLeft().lon, closeTo(-70, 0.00001));
|
assertThat(filter.topLeft().lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.bottomRight().lat, closeTo(30, 0.00001));
|
assertThat(filter.bottomRight().lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.bottomRight().lon, closeTo(-80, 0.00001));
|
assertThat(filter.bottomRight().lon(), closeTo(-80, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1849,10 +1849,10 @@ public class SimpleIndexQueryParserTests {
|
||||||
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
||||||
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.topLeft().lat, closeTo(40, 0.00001));
|
assertThat(filter.topLeft().lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.topLeft().lon, closeTo(-70, 0.00001));
|
assertThat(filter.topLeft().lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.bottomRight().lat, closeTo(30, 0.00001));
|
assertThat(filter.bottomRight().lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.bottomRight().lon, closeTo(-80, 0.00001));
|
assertThat(filter.bottomRight().lon(), closeTo(-80, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1864,10 +1864,10 @@ public class SimpleIndexQueryParserTests {
|
||||||
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
XConstantScoreQuery constantScoreQuery = (XConstantScoreQuery) parsedQuery;
|
||||||
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
InMemoryGeoBoundingBoxFilter filter = (InMemoryGeoBoundingBoxFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.topLeft().lat, closeTo(40, 0.00001));
|
assertThat(filter.topLeft().lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.topLeft().lon, closeTo(-70, 0.00001));
|
assertThat(filter.topLeft().lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.bottomRight().lat, closeTo(30, 0.00001));
|
assertThat(filter.bottomRight().lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.bottomRight().lon, closeTo(-80, 0.00001));
|
assertThat(filter.bottomRight().lon(), closeTo(-80, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1881,12 +1881,12 @@ public class SimpleIndexQueryParserTests {
|
||||||
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.points().length, equalTo(3));
|
assertThat(filter.points().length, equalTo(3));
|
||||||
assertThat(filter.points()[0].lat, closeTo(40, 0.00001));
|
assertThat(filter.points()[0].lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.points()[0].lon, closeTo(-70, 0.00001));
|
assertThat(filter.points()[0].lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.points()[1].lat, closeTo(30, 0.00001));
|
assertThat(filter.points()[1].lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.points()[1].lon, closeTo(-80, 0.00001));
|
assertThat(filter.points()[1].lon(), closeTo(-80, 0.00001));
|
||||||
assertThat(filter.points()[2].lat, closeTo(20, 0.00001));
|
assertThat(filter.points()[2].lat(), closeTo(20, 0.00001));
|
||||||
assertThat(filter.points()[2].lon, closeTo(-90, 0.00001));
|
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1899,12 +1899,12 @@ public class SimpleIndexQueryParserTests {
|
||||||
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.points().length, equalTo(3));
|
assertThat(filter.points().length, equalTo(3));
|
||||||
assertThat(filter.points()[0].lat, closeTo(40, 0.00001));
|
assertThat(filter.points()[0].lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.points()[0].lon, closeTo(-70, 0.00001));
|
assertThat(filter.points()[0].lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.points()[1].lat, closeTo(30, 0.00001));
|
assertThat(filter.points()[1].lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.points()[1].lon, closeTo(-80, 0.00001));
|
assertThat(filter.points()[1].lon(), closeTo(-80, 0.00001));
|
||||||
assertThat(filter.points()[2].lat, closeTo(20, 0.00001));
|
assertThat(filter.points()[2].lat(), closeTo(20, 0.00001));
|
||||||
assertThat(filter.points()[2].lon, closeTo(-90, 0.00001));
|
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1917,12 +1917,12 @@ public class SimpleIndexQueryParserTests {
|
||||||
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.points().length, equalTo(3));
|
assertThat(filter.points().length, equalTo(3));
|
||||||
assertThat(filter.points()[0].lat, closeTo(40, 0.00001));
|
assertThat(filter.points()[0].lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.points()[0].lon, closeTo(-70, 0.00001));
|
assertThat(filter.points()[0].lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.points()[1].lat, closeTo(30, 0.00001));
|
assertThat(filter.points()[1].lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.points()[1].lon, closeTo(-80, 0.00001));
|
assertThat(filter.points()[1].lon(), closeTo(-80, 0.00001));
|
||||||
assertThat(filter.points()[2].lat, closeTo(20, 0.00001));
|
assertThat(filter.points()[2].lat(), closeTo(20, 0.00001));
|
||||||
assertThat(filter.points()[2].lon, closeTo(-90, 0.00001));
|
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1935,12 +1935,12 @@ public class SimpleIndexQueryParserTests {
|
||||||
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.points().length, equalTo(3));
|
assertThat(filter.points().length, equalTo(3));
|
||||||
assertThat(filter.points()[0].lat, closeTo(40, 0.00001));
|
assertThat(filter.points()[0].lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.points()[0].lon, closeTo(-70, 0.00001));
|
assertThat(filter.points()[0].lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.points()[1].lat, closeTo(30, 0.00001));
|
assertThat(filter.points()[1].lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.points()[1].lon, closeTo(-80, 0.00001));
|
assertThat(filter.points()[1].lon(), closeTo(-80, 0.00001));
|
||||||
assertThat(filter.points()[2].lat, closeTo(20, 0.00001));
|
assertThat(filter.points()[2].lat(), closeTo(20, 0.00001));
|
||||||
assertThat(filter.points()[2].lon, closeTo(-90, 0.00001));
|
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1953,12 +1953,12 @@ public class SimpleIndexQueryParserTests {
|
||||||
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
GeoPolygonFilter filter = (GeoPolygonFilter) constantScoreQuery.getFilter();
|
||||||
assertThat(filter.fieldName(), equalTo("location"));
|
assertThat(filter.fieldName(), equalTo("location"));
|
||||||
assertThat(filter.points().length, equalTo(3));
|
assertThat(filter.points().length, equalTo(3));
|
||||||
assertThat(filter.points()[0].lat, closeTo(40, 0.00001));
|
assertThat(filter.points()[0].lat(), closeTo(40, 0.00001));
|
||||||
assertThat(filter.points()[0].lon, closeTo(-70, 0.00001));
|
assertThat(filter.points()[0].lon(), closeTo(-70, 0.00001));
|
||||||
assertThat(filter.points()[1].lat, closeTo(30, 0.00001));
|
assertThat(filter.points()[1].lat(), closeTo(30, 0.00001));
|
||||||
assertThat(filter.points()[1].lon, closeTo(-80, 0.00001));
|
assertThat(filter.points()[1].lon(), closeTo(-80, 0.00001));
|
||||||
assertThat(filter.points()[2].lat, closeTo(20, 0.00001));
|
assertThat(filter.points()[2].lat(), closeTo(20, 0.00001));
|
||||||
assertThat(filter.points()[2].lon, closeTo(-90, 0.00001));
|
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,15 +19,13 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.search.geo;
|
package org.elasticsearch.test.unit.index.search.geo;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.geo.GeoDistance;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.common.unit.DistanceUnit;
|
import org.elasticsearch.common.unit.DistanceUnit;
|
||||||
import org.elasticsearch.index.search.geo.GeoDistance;
|
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
|
||||||
import static org.hamcrest.Matchers.lessThan;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -49,22 +47,22 @@ public class GeoDistanceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testArcDistanceVsPlaneInEllipsis() {
|
public void testArcDistanceVsPlaneInEllipsis() {
|
||||||
Point centre = new Point(48.8534100, 2.3488000);
|
GeoPoint centre = new GeoPoint(48.8534100, 2.3488000);
|
||||||
Point northernPoint = new Point(48.8801108681, 2.35152032666);
|
GeoPoint northernPoint = new GeoPoint(48.8801108681, 2.35152032666);
|
||||||
Point westernPoint = new Point(48.85265, 2.308896);
|
GeoPoint westernPoint = new GeoPoint(48.85265, 2.308896);
|
||||||
|
|
||||||
// With GeoDistance.ARC both the northern and western points are within the 4km range
|
// With GeoDistance.ARC both the northern and western points are within the 4km range
|
||||||
assertThat(GeoDistance.ARC.calculate(centre.lat, centre.lon, northernPoint.lat,
|
assertThat(GeoDistance.ARC.calculate(centre.lat(), centre.lon(), northernPoint.lat(),
|
||||||
northernPoint.lon, DistanceUnit.KILOMETERS), lessThan(4D));
|
northernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));
|
||||||
assertThat(GeoDistance.ARC.calculate(centre.lat, centre.lon, westernPoint.lat,
|
assertThat(GeoDistance.ARC.calculate(centre.lat(), centre.lon(), westernPoint.lat(),
|
||||||
westernPoint.lon, DistanceUnit.KILOMETERS), lessThan(4D));
|
westernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));
|
||||||
|
|
||||||
// With GeoDistance.PLANE, only the northern point is within the 4km range,
|
// With GeoDistance.PLANE, only the northern point is within the 4km range,
|
||||||
// the western point is outside of the range due to the simple math it employs,
|
// the western point is outside of the range due to the simple math it employs,
|
||||||
// meaning results will appear elliptical
|
// meaning results will appear elliptical
|
||||||
assertThat(GeoDistance.PLANE.calculate(centre.lat, centre.lon, northernPoint.lat,
|
assertThat(GeoDistance.PLANE.calculate(centre.lat(), centre.lon(), northernPoint.lat(),
|
||||||
northernPoint.lon, DistanceUnit.KILOMETERS), lessThan(4D));
|
northernPoint.lon(), DistanceUnit.KILOMETERS), lessThan(4D));
|
||||||
assertThat(GeoDistance.PLANE.calculate(centre.lat, centre.lon, westernPoint.lat,
|
assertThat(GeoDistance.PLANE.calculate(centre.lat(), centre.lon(), westernPoint.lat(),
|
||||||
westernPoint.lon, DistanceUnit.KILOMETERS), greaterThan(4D));
|
westernPoint.lon(), DistanceUnit.KILOMETERS), greaterThan(4D));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.search.geo;
|
package org.elasticsearch.test.unit.index.search.geo;
|
||||||
|
|
||||||
import org.elasticsearch.index.search.geo.GeoHashUtils;
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -50,10 +51,10 @@ public class GeoHashUtilsTests {
|
||||||
public void testDecodePreciseLongitudeLatitude() {
|
public void testDecodePreciseLongitudeLatitude() {
|
||||||
String hash = GeoHashUtils.encode(52.3738007, 4.8909347);
|
String hash = GeoHashUtils.encode(52.3738007, 4.8909347);
|
||||||
|
|
||||||
double[] latitudeLongitude = GeoHashUtils.decode(hash);
|
GeoPoint point = GeoHashUtils.decode(hash);
|
||||||
|
|
||||||
assertEquals(52.3738007, latitudeLongitude[0], 0.00001D);
|
assertEquals(52.3738007, point.lat(), 0.00001D);
|
||||||
assertEquals(4.8909347, latitudeLongitude[1], 0.00001D);
|
assertEquals(4.8909347, point.lon(), 0.00001D);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,10 +65,10 @@ public class GeoHashUtilsTests {
|
||||||
public void testDecodeImpreciseLongitudeLatitude() {
|
public void testDecodeImpreciseLongitudeLatitude() {
|
||||||
String hash = GeoHashUtils.encode(84.6, 10.5);
|
String hash = GeoHashUtils.encode(84.6, 10.5);
|
||||||
|
|
||||||
double[] latitudeLongitude = GeoHashUtils.decode(hash);
|
GeoPoint point = GeoHashUtils.decode(hash);
|
||||||
|
|
||||||
assertEquals(84.6, latitudeLongitude[0], 0.00001D);
|
assertEquals(84.6, point.lat(), 0.00001D);
|
||||||
assertEquals(10.5, latitudeLongitude[1], 0.00001D);
|
assertEquals(10.5, point.lon(), 0.00001D);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -78,16 +79,10 @@ public class GeoHashUtilsTests {
|
||||||
public void testDecodeEncode() {
|
public void testDecodeEncode() {
|
||||||
String geoHash = "u173zq37x014";
|
String geoHash = "u173zq37x014";
|
||||||
assertEquals(geoHash, GeoHashUtils.encode(52.3738007, 4.8909347));
|
assertEquals(geoHash, GeoHashUtils.encode(52.3738007, 4.8909347));
|
||||||
double[] decode = GeoHashUtils.decode(geoHash);
|
GeoPoint decode = GeoHashUtils.decode(geoHash);
|
||||||
assertEquals(52.37380061d, decode[0], 0.000001d);
|
assertEquals(52.37380061d, decode.lat(), 0.000001d);
|
||||||
assertEquals(4.8909343d, decode[1], 0.000001d);
|
assertEquals(4.8909343d, decode.lon(), 0.000001d);
|
||||||
|
|
||||||
assertEquals(geoHash, GeoHashUtils.encode(decode[0], decode[1]));
|
assertEquals(geoHash, GeoHashUtils.encode(decode.lat(), decode.lon()));
|
||||||
|
|
||||||
geoHash = "u173";
|
|
||||||
decode = GeoHashUtils.decode("u173");
|
|
||||||
geoHash = GeoHashUtils.encode(decode[0], decode[1]);
|
|
||||||
assertEquals(decode[0], GeoHashUtils.decode(geoHash)[0], 0.000001d);
|
|
||||||
assertEquals(decode[1], GeoHashUtils.decode(geoHash)[1], 0.000001d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.test.unit.index.search.geo;
|
package org.elasticsearch.test.unit.index.search.geo;
|
||||||
|
|
||||||
import org.elasticsearch.index.search.geo.GeoUtils;
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
import org.elasticsearch.index.search.geo.Point;
|
import org.elasticsearch.common.geo.GeoUtils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -85,7 +85,7 @@ public class GeoUtilsTests {
|
||||||
// Now with points, to check for longitude shifting with latitude normalization
|
// Now with points, to check for longitude shifting with latitude normalization
|
||||||
// We've gone past the north pole and down the other side, the longitude will
|
// We've gone past the north pole and down the other side, the longitude will
|
||||||
// be shifted by 180
|
// be shifted by 180
|
||||||
assertNormalizedPoint(new Point(90.5, 10), new Point(89.5, -170));
|
assertNormalizedPoint(new GeoPoint(90.5, 10), new GeoPoint(89.5, -170));
|
||||||
|
|
||||||
// Every 10-units, multiple full turns
|
// Every 10-units, multiple full turns
|
||||||
for (int shift = -20; shift <= 20; ++shift) {
|
for (int shift = -20; shift <= 20; ++shift) {
|
||||||
|
@ -199,7 +199,7 @@ public class GeoUtilsTests {
|
||||||
assertThat(GeoUtils.normalizeLat(+18000000000091.0), equalTo(GeoUtils.normalizeLat(+091.0)));
|
assertThat(GeoUtils.normalizeLat(+18000000000091.0), equalTo(GeoUtils.normalizeLat(+091.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNormalizedPoint(Point input, Point expected) {
|
private static void assertNormalizedPoint(GeoPoint input, GeoPoint expected) {
|
||||||
GeoUtils.normalizePoint(input);
|
GeoUtils.normalizePoint(input);
|
||||||
assertThat(input, equalTo(expected));
|
assertThat(input, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue