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.
nearest()
for finding the k-nearest neighbors by distance.
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 FieldType |
TYPE
Type for an indexed LatLonPoint
|
boost, fieldsData, name, tokenStream, type
Constructor and Description |
---|
LatLonPoint(String name,
double latitude,
double longitude)
Creates a new LatLonPoint with the specified latitude and longitude
|
Modifier and Type | Method and Description |
---|---|
static TopFieldDocs |
nearest(IndexSearcher searcher,
String field,
double latitude,
double longitude,
int n)
Finds the
n nearest indexed points to the provided point, according to Haversine distance. |
static Query |
newBoxQuery(String field,
double minLatitude,
double maxLatitude,
double minLongitude,
double maxLongitude)
Create a query for matching a bounding box.
|
static Query |
newDistanceQuery(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(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
|
String |
toString() |
binaryValue, boost, fieldType, name, numericValue, readerValue, setBoost, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
public static final FieldType TYPE
Each point stores two dimensions with 4 bytes per dimension.
public LatLonPoint(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.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.IllegalArgumentException
- if latitude or longitude are out of boundspublic static Query newBoxQuery(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.IllegalArgumentException
- if field
is null, or the box has invalid coordinates.public static Query newDistanceQuery(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.IllegalArgumentException
- if field
is null, location has invalid coordinates, or radius is invalid.public static Query newPolygonQuery(String field, Polygon... polygons)
field
- field name. must not be null.polygons
- array of polygons. must not be null or emptyIllegalArgumentException
- if field
is null, polygons
is null or emptyPolygon
public static TopFieldDocs nearest(IndexSearcher searcher, String field, double latitude, double longitude, int n) throws IOException
n
nearest indexed points to the provided point, according to Haversine distance.
This is functionally equivalent to running MatchAllDocsQuery
with a LatLonDocValuesField.newDistanceSort(java.lang.String, double, double)
,
but is far more efficient since it takes advantage of properties the indexed BKD tree. Currently this
only works with Lucene60PointsFormat
(used by the default codec). Multi-valued fields are
currently not de-duplicated, so if a document had multiple instances of the specified field that
make it into the top n, that document will appear more than once.
Documents are ordered by ascending distance from the location. The value returned in FieldDoc
for
the hits contains a Double instance with the distance in meters.
searcher
- IndexSearcher to find nearest points from.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.n
- the number of nearest neighbors to retrieve.FieldDoc
is the distance in metersIllegalArgumentException
- if the underlying PointValues is not a Lucene60PointsReader
(this is a current limitation), or
if field
or searcher
is null, or if latitude
, longitude
or n
are out-of-boundsIOException
- if an IOException occurs while finding the points.Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.