public class LatLonPoint extends Field
Finding all documents within a range at search time is efficient. Multiple values for the same field in one document is allowed.
This field defines static factory methods for common operations:
newBoxQuery()
for matching points within a bounding box.
newDistanceQuery()
for matching points within a specified distance.
newPolygonQuery()
for matching points within an arbitrary polygon.
If you also need per-document operations such as sort by distance, add a separate LatLonDocValuesField
instance.
If you also need to store the value, you should add a separate StoredField
instance.
WARNING: Values are indexed with some loss of precision from the
original double
values (4.190951585769653E-8 for the latitude component
and 8.381903171539307E-8 for longitude).
PointValues
,
LatLonDocValuesField
Field.Store
Modifier and Type | Field and Description |
---|---|
static int |
BYTES
LatLonPoint is encoded as integer values so number of bytes is 4
|
static FieldType |
TYPE
Type for an indexed LatLonPoint
|
fieldsData, name, tokenStream, type
Constructor and Description |
---|
LatLonPoint(java.lang.String name,
double latitude,
double longitude)
Creates a new LatLonPoint with the specified latitude and longitude
|
Modifier and Type | Method and Description |
---|---|
(package private) static void |
checkCompatible(FieldInfo fieldInfo)
helper: checks a fieldinfo and throws exception if its definitely not a LatLonPoint
|
private static byte[] |
encode(double latitude,
double longitude)
sugar encodes a single point as a byte array
|
private static byte[] |
encodeCeil(double latitude,
double longitude)
sugar encodes a single point as a byte array, rounding values up
|
private static Query |
newBoxInternal(java.lang.String field,
byte[] min,
byte[] max) |
static Query |
newBoxQuery(java.lang.String field,
double minLatitude,
double maxLatitude,
double minLongitude,
double maxLongitude)
Create a query for matching a bounding box.
|
static Query |
newDistanceFeatureQuery(java.lang.String field,
float weight,
double originLat,
double originLon,
double pivotDistanceMeters)
Given a field that indexes point values into a
LatLonPoint
and doc values into LatLonDocValuesField , this returns a query that scores
documents based on their haversine distance in meters to (originLat, originLon) :
score = weight * pivotDistanceMeters / (pivotDistanceMeters + distance) , ie. |
static Query |
newDistanceQuery(java.lang.String field,
double latitude,
double longitude,
double radiusMeters)
Create a query for matching points within the specified distance of the supplied location.
|
static Query |
newPolygonQuery(java.lang.String field,
Polygon... polygons)
Create a query for matching one or more polygons.
|
void |
setLocationValue(double latitude,
double longitude)
Change the values of this field
|
java.lang.String |
toString()
Prints a Field for human consumption.
|
binaryValue, fieldType, getCharSequenceValue, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
public static final int BYTES
public static final FieldType TYPE
Each point stores two dimensions with 4 bytes per dimension.
public LatLonPoint(java.lang.String name, double latitude, double longitude)
name
- field namelatitude
- latitude value: must be within standard +/-90 coordinate bounds.longitude
- longitude value: must be within standard +/-180 coordinate bounds.java.lang.IllegalArgumentException
- if the field name is null or latitude or longitude are out of boundspublic void setLocationValue(double latitude, double longitude)
latitude
- latitude value: must be within standard +/-90 coordinate bounds.longitude
- longitude value: must be within standard +/-180 coordinate bounds.java.lang.IllegalArgumentException
- if latitude or longitude are out of boundspublic java.lang.String toString()
Field
private static byte[] encode(double latitude, double longitude)
private static byte[] encodeCeil(double latitude, double longitude)
static void checkCompatible(FieldInfo fieldInfo)
public static Query newBoxQuery(java.lang.String field, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude)
The box may cross over the dateline.
field
- field name. must not be null.minLatitude
- latitude lower bound: must be within standard +/-90 coordinate bounds.maxLatitude
- latitude upper bound: must be within standard +/-90 coordinate bounds.minLongitude
- longitude lower bound: must be within standard +/-180 coordinate bounds.maxLongitude
- longitude upper bound: must be within standard +/-180 coordinate bounds.java.lang.IllegalArgumentException
- if field
is null, or the box has invalid coordinates.private static Query newBoxInternal(java.lang.String field, byte[] min, byte[] max)
public static Query newDistanceQuery(java.lang.String field, double latitude, double longitude, double radiusMeters)
field
- field name. must not be null.latitude
- latitude at the center: must be within standard +/-90 coordinate bounds.longitude
- longitude at the center: must be within standard +/-180 coordinate bounds.radiusMeters
- maximum distance from the center in meters: must be non-negative and finite.java.lang.IllegalArgumentException
- if field
is null, location has invalid coordinates, or radius is invalid.public static Query newPolygonQuery(java.lang.String field, Polygon... polygons)
field
- field name. must not be null.polygons
- array of polygons. must not be null or emptyjava.lang.IllegalArgumentException
- if field
is null, polygons
is null or emptyPolygon
public static Query newDistanceFeatureQuery(java.lang.String field, float weight, double originLat, double originLon, double pivotDistanceMeters)
LatLonPoint
and doc values into LatLonDocValuesField
, this returns a query that scores
documents based on their haversine distance in meters to (originLat, originLon)
:
score = weight * pivotDistanceMeters / (pivotDistanceMeters + distance)
, ie.
score is in the [0, weight]
range, is equal to weight
when
the document's value is equal to (originLat, originLon)
and is equal to
weight/2
when the document's value is distant of
pivotDistanceMeters
from (originLat, originLon)
.
In case of multi-valued fields, only the closest point to (originLat, originLon)
will be considered.
This query is typically useful to boost results based on distance by adding
this query to a BooleanClause.Occur.SHOULD
clause of a BooleanQuery
.