org.apache.lucene.spatial.geopoint.document

Class GeoPointField

  • All Implemented Interfaces:
    IndexableField


    public final class GeoPointField
    extends Field

    Field that indexes latitude longitude decimal-degree values for efficient encoding, sorting, and querying. This Geo capability is intended to provide a basic and efficient out of the box field type for indexing and querying 2 dimensional points in WGS-84 decimal degrees. An example usage is as follows:

      document.add(new GeoPointField(name, -96.33, 32.66, Field.Store.NO));
     

    To perform simple geospatial queries against a GeoPointField, see GeoPointInBBoxQuery, GeoPointInPolygonQuery, or GeoPointDistanceQuery NOTE: This indexes only high precision encoded terms which may result in visiting a high number of terms for large queries. See LUCENE-6481 for a future improvement.

    • Field Detail

      • BITS

        public static final short BITS
        number of bits used for quantizing latitude and longitude values
        See Also:
        Constant Field Values
      • PREFIX_TYPE_NOT_STORED

        public static final FieldType PREFIX_TYPE_NOT_STORED
        Type for a GeoPointField that is not stored: normalization factors, frequencies, and positions are omitted.
      • PREFIX_TYPE_STORED

        public static final FieldType PREFIX_TYPE_STORED
        Type for a stored GeoPointField: normalization factors, frequencies, and positions are omitted.
    • Method Detail

      • tokenStream

        public TokenStream tokenStream(Analyzer analyzer,
                                       TokenStream reuse)
        Description copied from interface: IndexableField
        Creates the TokenStream used for indexing this field. If appropriate, implementations should use the given Analyzer to create the TokenStreams.
        Specified by:
        tokenStream in interface IndexableField
        Overrides:
        tokenStream in class Field
        Parameters:
        analyzer - Analyzer that should be used to create the TokenStreams from
        reuse - TokenStream for a previous instance of this field name. This allows custom field types (like StringField and NumericField) that do not use the analyzer to still have good performance. Note: the passed-in type may be inappropriate, for example if you mix up different types of Fields for the same field name. So it's the responsibility of the implementation to check.
        Returns:
        TokenStream value for indexing the document. Should always return a non-null value if the field is to be indexed
      • getLat

        public double getLat()
        access latitude value
      • getLon

        public double getLon()
        access longitude value
      • encodeLatLon

        public static long encodeLatLon(double lat,
                                        double lon)
        31 bit encoding utils *
      • decodeLongitude

        public static final double decodeLongitude(long hash)
        decode longitude value from morton encoded geo point
      • decodeLatitude

        public static final double decodeLatitude(long hash)
        decode latitude value from morton encoded geo point
      • prefixCodedToGeoCoded

        public static long prefixCodedToGeoCoded(BytesRef val)
        Convert a prefix coded geo term back into the geocoded morton long