Class LatLonPointPrototypeQueries


  • public class LatLonPointPrototypeQueries
    extends java.lang.Object
    Holder class for prototype sandboxed queries When the query graduates from sandbox, these static calls should be placed in LatLonPoint
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TopFieldDocs nearest​(IndexSearcher searcher, java.lang.String field, double latitude, double longitude, int n)
      Finds the n nearest indexed points to the provided point, according to Haversine distance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LatLonPointPrototypeQueries

        private LatLonPointPrototypeQueries()
    • Method Detail

      • nearest

        public static TopFieldDocs nearest​(IndexSearcher searcher,
                                           java.lang.String field,
                                           double latitude,
                                           double longitude,
                                           int n)
                                    throws java.io.IOException
        Finds the 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 Lucene86PointsFormat (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.

        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.
        Returns:
        TopFieldDocs containing documents ordered by distance, where the field value for each FieldDoc is the distance in meters
        Throws:
        java.lang.IllegalArgumentException - 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-bounds
        java.io.IOException - if an IOException occurs while finding the points.