Class IntRange

  • All Implemented Interfaces:
    IndexableField

    public class IntRange
    extends Field
    An indexed Integer Range field.

    This field indexes dimensional ranges defined as min/max pairs. It supports up to a maximum of 4 dimensions (indexed as 8 numeric values). With 1 dimension representing a single integer range, 2 dimensions representing a bounding box, 3 dimensions a bounding cube, and 4 dimensions a tesseract.

    Multiple values for the same field in one document is supported, and open ended ranges can be defined using Integer.MIN_VALUE and Integer.MAX_VALUE.

    This field defines the following static factory methods for common search operations over integer ranges:

    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.lucene.document.Field

        Field.Store
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BYTES
      stores integer values so number of bytes is 4
    • Constructor Summary

      Constructors 
      Constructor Description
      IntRange​(java.lang.String name, int[] min, int[] max)
      Create a new IntRange type, from min/max parallel arrays
    • Field Detail

      • BYTES

        public static final int BYTES
        stores integer values so number of bytes is 4
        See Also:
        Constant Field Values
    • Constructor Detail

      • IntRange

        public IntRange​(java.lang.String name,
                        int[] min,
                        int[] max)
        Create a new IntRange type, from min/max parallel arrays
        Parameters:
        name - field name. must not be null.
        min - range min values; each entry is the min value for the dimension
        max - range max values; each entry is the max value for the dimension
    • Method Detail

      • getType

        private static FieldType getType​(int dimensions)
        set the field type
      • setRangeValues

        public void setRangeValues​(int[] min,
                                   int[] max)
        Changes the values of the field.
        Parameters:
        min - array of min values. (accepts Integer.NEGATIVE_INFINITY)
        max - array of max values. (accepts Integer.POSITIVE_INFINITY)
        Throws:
        java.lang.IllegalArgumentException - if min or max is invalid
      • checkArgs

        private static void checkArgs​(int[] min,
                                      int[] max)
        validate the arguments
      • encode

        static byte[] encode​(int[] min,
                             int[] max)
        Encodes the min, max ranges into a byte array
      • verifyAndEncode

        static void verifyAndEncode​(int[] min,
                                    int[] max,
                                    byte[] bytes)
        encode the ranges into a sortable byte array (Double.NaN not allowed)

        example for 4 dimensions (8 bytes per dimension value): minD1 ... minD4 | maxD1 ... maxD4

      • encode

        private static void encode​(int val,
                                   byte[] bytes,
                                   int offset)
        encode the given value into the byte array at the defined offset
      • getMin

        public int getMin​(int dimension)
        Get the min value for the given dimension
        Parameters:
        dimension - the dimension, always positive
        Returns:
        the decoded min value
      • getMax

        public int getMax​(int dimension)
        Get the max value for the given dimension
        Parameters:
        dimension - the dimension, always positive
        Returns:
        the decoded max value
      • decodeMin

        static int decodeMin​(byte[] b,
                             int dimension)
        decodes the min value (for the defined dimension) from the encoded input byte array
      • decodeMax

        static int decodeMax​(byte[] b,
                             int dimension)
        decodes the max value (for the defined dimension) from the encoded input byte array
      • newIntersectsQuery

        public static Query newIntersectsQuery​(java.lang.String field,
                                               int[] min,
                                               int[] max)
        Create a query for matching indexed ranges that intersect the defined range.
        Parameters:
        field - field name. must not be null.
        min - array of min values. (accepts Integer.MIN_VALUE)
        max - array of max values. (accepts Integer.MAX_VALUE)
        Returns:
        query for matching intersecting ranges (overlap, within, or contains)
        Throws:
        java.lang.IllegalArgumentException - if field is null, min or max is invalid
      • newContainsQuery

        public static Query newContainsQuery​(java.lang.String field,
                                             int[] min,
                                             int[] max)
        Create a query for matching indexed ranges that contain the defined range.
        Parameters:
        field - field name. must not be null.
        min - array of min values. (accepts Integer.MIN_VALUE)
        max - array of max values. (accepts Integer.MAX_VALUE)
        Returns:
        query for matching ranges that contain the defined range
        Throws:
        java.lang.IllegalArgumentException - if field is null, min or max is invalid
      • newWithinQuery

        public static Query newWithinQuery​(java.lang.String field,
                                           int[] min,
                                           int[] max)
        Create a query for matching indexed ranges that are within the defined range.
        Parameters:
        field - field name. must not be null.
        min - array of min values. (accepts Integer.MIN_VALUE)
        max - array of max values. (accepts Integer.MAX_VALUE)
        Returns:
        query for matching ranges within the defined range
        Throws:
        java.lang.IllegalArgumentException - if field is null, min or max is invalid
      • newCrossesQuery

        public static Query newCrossesQuery​(java.lang.String field,
                                            int[] min,
                                            int[] max)
        Create a query for matching indexed ranges that cross the defined range. A CROSSES is defined as any set of ranges that are not disjoint and not wholly contained by the query. Effectively, its the complement of union(WITHIN, DISJOINT).
        Parameters:
        field - field name. must not be null.
        min - array of min values. (accepts Integer.MIN_VALUE)
        max - array of max values. (accepts Integer.MAX_VALUE)
        Returns:
        query for matching ranges within the defined range
        Throws:
        java.lang.IllegalArgumentException - if field is null, min or max is invalid
      • newRelationQuery

        private static Query newRelationQuery​(java.lang.String field,
                                              int[] min,
                                              int[] max,
                                              RangeFieldQuery.QueryType relation)
        helper method for creating the desired relational query
      • toString

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

        private static java.lang.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
        Returns:
        The string representation for the range at the provided dimension