nearest

fun nearest(searcher: IndexSearcher, field: String, latitude: Double, longitude: Double, n: Int): TopFieldDocs

Finds the n nearest indexed points to the provided point, according to Haversine distance.

This is functionally equivalent to running MatchAllDocsQuery with a , but is far more efficient since it takes advantage of properties the indexed BKD tree. 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 [ ] for the hits contains a Double instance with the distance in meters.

Return

TopFieldDocs containing documents ordered by distance, where the field value for each FieldDoc is the distance in meters

Parameters

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.

Throws

if field or searcher is null, or if latitude, longitude or n are out-of-bounds

IOException

if an IOException occurs while finding the points.