Class XYDocValuesField

java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.XYDocValuesField
All Implemented Interfaces:
IndexableField

public class XYDocValuesField extends Field
An per-document location field.

Sorting by distance is efficient. Multiple values for the same field in one document is allowed.

This field defines static factory methods for common operations:

If you also need query operations, you should add a separate XYPointField instance. If you also need to store the value, you should add a separate StoredField instance.

See Also:
  • Field Details

    • TYPE

      public static final FieldType TYPE
      Type for a XYDocValuesField

      Each value stores a 64-bit long where the upper 32 bits are the encoded x value, and the lower 32 bits are the encoded y value.

      See Also:
  • Constructor Details

    • XYDocValuesField

      public XYDocValuesField(String name, float x, float y)
      Creates a new XYDocValuesField with the specified x and y
      Parameters:
      name - field name
      x - x value.
      y - y values.
      Throws:
      IllegalArgumentException - if the field name is null or x or y are infinite or NaN.
  • Method Details

    • setLocationValue

      public void setLocationValue(float x, float y)
      Change the values of this field
      Parameters:
      x - x value.
      y - y value.
      Throws:
      IllegalArgumentException - if x or y are infinite or NaN.
    • toString

      public String toString()
      Description copied from class: Field
      Prints a Field for human consumption.
      Overrides:
      toString in class Field
    • newDistanceSort

      public static SortField newDistanceSort(String field, float x, float y)
      Creates a SortField for sorting by distance from a location.

      This sort orders documents by ascending distance from the location. The value returned in FieldDoc for the hits contains a Double instance with the distance in meters.

      If a document is missing the field, then by default it is treated as having Double.POSITIVE_INFINITY distance (missing values sort last).

      If a document contains multiple values for the field, the closest distance to the location is used.

      Parameters:
      field - field name. must not be null.
      x - x at the center.
      y - y at the center.
      Returns:
      SortField ordering documents by distance
      Throws:
      IllegalArgumentException - if field is null or location has invalid coordinates.
    • newSlowBoxQuery

      public static Query newSlowBoxQuery(String field, float minX, float maxX, float minY, float maxY)
      Create a query for matching a bounding box using doc values. This query is usually slow as it does not use an index structure and needs to verify documents one-by-one in order to know whether they match. It is best used wrapped in an IndexOrDocValuesQuery alongside a XYPointField.newBoxQuery(java.lang.String, float, float, float, float).
    • newSlowDistanceQuery

      public static Query newSlowDistanceQuery(String field, float x, float y, float radius)
      Create a query for matching points within the specified distance of the supplied location. This query is usually slow as it does not use an index structure and needs to verify documents one-by-one in order to know whether they match. It is best used wrapped in an IndexOrDocValuesQuery alongside a XYPointField.newDistanceQuery(java.lang.String, float, float, float).
      Parameters:
      field - field name. must not be null.
      x - x at the center.
      y - y at the center: must be within standard +/-180 coordinate bounds.
      radius - maximum distance from the center in cartesian distance: must be non-negative and finite.
      Returns:
      query matching points within this distance
      Throws:
      IllegalArgumentException - if field is null, location has invalid coordinates, or radius is invalid.
    • newSlowPolygonQuery

      public static Query newSlowPolygonQuery(String field, XYPolygon... polygons)
      Create a query for matching points within the supplied polygons. This query is usually slow as it does not use an index structure and needs to verify documents one-by-one in order to know whether they match. It is best used wrapped in an IndexOrDocValuesQuery alongside a XYPointField.newPolygonQuery(String, XYPolygon...).
      Parameters:
      field - field name. must not be null.
      polygons - array of polygons. must not be null or empty.
      Returns:
      query matching points within the given polygons.
      Throws:
      IllegalArgumentException - if field is null or polygons is empty or contain a null polygon.
    • newSlowGeometryQuery

      public static Query newSlowGeometryQuery(String field, XYGeometry... geometries)
      Create a query for matching points within the supplied geometries. XYLine geometries are not supported. This query is usually slow as it does not use an index structure and needs to verify documents one-by-one in order to know whether they match. It is best used wrapped in an IndexOrDocValuesQuery alongside a XYPointField.newGeometryQuery(String, XYGeometry...).
      Parameters:
      field - field name. must not be null.
      geometries - array of XY geometries. must not be null or empty.
      Returns:
      query matching points within the given geometries.
      Throws:
      IllegalArgumentException - if field is null, polygons is null, empty or contains a null or XYLine geometry.