Class InetAddressRange

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

public class InetAddressRange extends Field
An indexed InetAddress Range Field

This field indexes an InetAddress range defined as a min/max pairs. It is single dimension only (indexed as two 16 byte paired values).

Multiple values are supported.

This field defines the following static factory methods for common search operations over Ip Ranges

  • Field Details

    • BYTES

      public static final int BYTES
      The number of bytes per dimension : sync w/ InetAddressPoint
      See Also:
    • TYPE

      private static final FieldType TYPE
  • Constructor Details

    • InetAddressRange

      public InetAddressRange(String name, InetAddress min, InetAddress max)
      Create a new InetAddressRange from min/max value
      Parameters:
      name - field name. must not be null.
      min - range min value; defined as an InetAddress
      max - range max value; defined as an InetAddress
  • Method Details

    • setRangeValues

      public void setRangeValues(InetAddress min, InetAddress max)
      Change (or set) the min/max values of the field.
      Parameters:
      min - range min value; defined as an InetAddress
      max - range max value; defined as an InetAddress
    • encode

      private static void encode(InetAddress min, InetAddress max, byte[] bytes)
      encode the min/max range into the provided byte array
    • encode

      private static byte[] encode(InetAddress min, InetAddress max)
      encode the min/max range and return the byte array
    • newIntersectsQuery

      public static Query newIntersectsQuery(String field, InetAddress min, InetAddress max)
      Create a query for matching indexed ip ranges that INTERSECT the defined range.
      Parameters:
      field - field name. must not be null.
      min - range min value; provided as an InetAddress
      max - range max value; provided as an InetAddress
      Returns:
      query for matching intersecting ranges (overlap, within, crosses, or contains)
      Throws:
      IllegalArgumentException - if field is null, min or max is invalid
    • newContainsQuery

      public static Query newContainsQuery(String field, InetAddress min, InetAddress max)
      Create a query for matching indexed ip ranges that CONTAINS the defined range.
      Parameters:
      field - field name. must not be null.
      min - range min value; provided as an InetAddress
      max - range max value; provided as an InetAddress
      Returns:
      query for matching intersecting ranges (overlap, within, crosses, or contains)
      Throws:
      IllegalArgumentException - if field is null, min or max is invalid
    • newWithinQuery

      public static Query newWithinQuery(String field, InetAddress min, InetAddress max)
      Create a query for matching indexed ip ranges that are WITHIN the defined range.
      Parameters:
      field - field name. must not be null.
      min - range min value; provided as an InetAddress
      max - range max value; provided as an InetAddress
      Returns:
      query for matching intersecting ranges (overlap, within, crosses, or contains)
      Throws:
      IllegalArgumentException - if field is null, min or max is invalid
    • newCrossesQuery

      public static Query newCrossesQuery(String field, InetAddress min, InetAddress max)
      Create a query for matching indexed ip ranges that CROSS the defined range.
      Parameters:
      field - field name. must not be null.
      min - range min value; provided as an InetAddress
      max - range max value; provided as an InetAddress
      Returns:
      query for matching intersecting ranges (overlap, within, crosses, or contains)
      Throws:
      IllegalArgumentException - if field is null, min or max is invalid
    • newRelationQuery

      private static Query newRelationQuery(String field, InetAddress min, InetAddress max, RangeFieldQuery.QueryType relation)
      helper method for creating the desired relational query
    • toString

      private static String toString(byte[] ranges, int dimension)
      Returns the String representation for the range at the given dimension
      Parameters:
      ranges - the encoded ranges, never null
      dimension - the dimension of interest (not used for this field)
      Returns:
      The string representation for the range at the provided dimension