public class FloatRange extends 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 float 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
Float.NEGATIVE_INFINITY
and Float.POSITIVE_INFINITY
.
This field defines the following static factory methods for common search operations over float ranges:
newIntersectsQuery()
matches ranges that intersect the defined search range.
newWithinQuery()
matches ranges that are within the defined search range.
newContainsQuery()
matches ranges that contain the defined search range.
Field.Store
Modifier and Type | Field and Description |
---|---|
static int |
BYTES
stores float values so number of bytes is 4
|
fieldsData, name, tokenStream, type
Constructor and Description |
---|
FloatRange(java.lang.String name,
float[] min,
float[] max)
Create a new FloatRange type, from min/max parallel arrays
|
Modifier and Type | Method and Description |
---|---|
private static void |
checkArgs(float[] min,
float[] max)
validate the arguments
|
(package private) static float |
decodeMax(byte[] b,
int dimension)
decodes the max value (for the defined dimension) from the encoded input byte array
|
(package private) static float |
decodeMin(byte[] b,
int dimension)
decodes the min value (for the defined dimension) from the encoded input byte array
|
private static byte[] |
encode(float[] min,
float[] max)
Encodes the min, max ranges into a byte array
|
private static void |
encode(float val,
byte[] bytes,
int offset)
encode the given value into the byte array at the defined offset
|
float |
getMax(int dimension)
Get the max value for the given dimension
|
float |
getMin(int dimension)
Get the min value for the given dimension
|
private static FieldType |
getType(int dimensions)
set the field type
|
static Query |
newContainsQuery(java.lang.String field,
float[] min,
float[] max)
Create a query for matching indexed float ranges that contain the defined range.
|
static Query |
newCrossesQuery(java.lang.String field,
float[] min,
float[] max)
Create a query for matching indexed ranges that cross the defined range.
|
static Query |
newIntersectsQuery(java.lang.String field,
float[] min,
float[] max)
Create a query for matching indexed ranges that intersect the defined range.
|
private static Query |
newRelationQuery(java.lang.String field,
float[] min,
float[] max,
RangeFieldQuery.QueryType relation)
helper method for creating the desired relational query
|
static Query |
newWithinQuery(java.lang.String field,
float[] min,
float[] max)
Create a query for matching indexed ranges that are within the defined range.
|
void |
setRangeValues(float[] min,
float[] max)
Changes the values of the field.
|
java.lang.String |
toString()
Prints a Field for human consumption.
|
private static java.lang.String |
toString(byte[] ranges,
int dimension)
Returns the String representation for the range at the given dimension
|
(package private) static void |
verifyAndEncode(float[] min,
float[] max,
byte[] bytes)
encode the ranges into a sortable byte array (
Float.NaN not allowed) |
binaryValue, fieldType, getCharSequenceValue, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
public static final int BYTES
public FloatRange(java.lang.String name, float[] min, float[] max)
name
- field name. must not be null.min
- range min values; each entry is the min value for the dimensionmax
- range max values; each entry is the max value for the dimensionprivate static FieldType getType(int dimensions)
public void setRangeValues(float[] min, float[] max)
min
- array of min values. (accepts Float.NEGATIVE_INFINITY
)max
- array of max values. (accepts Float.POSITIVE_INFINITY
)java.lang.IllegalArgumentException
- if min
or max
is invalidprivate static void checkArgs(float[] min, float[] max)
private static byte[] encode(float[] min, float[] max)
static void verifyAndEncode(float[] min, float[] max, byte[] bytes)
Float.NaN
not allowed)
example for 4 dimensions (8 bytes per dimension value): minD1 ... minD4 | maxD1 ... maxD4
private static void encode(float val, byte[] bytes, int offset)
public float getMin(int dimension)
dimension
- the dimension, always positivepublic float getMax(int dimension)
dimension
- the dimension, always positivestatic float decodeMin(byte[] b, int dimension)
static float decodeMax(byte[] b, int dimension)
public static Query newIntersectsQuery(java.lang.String field, float[] min, float[] max)
field
- field name. must not be null.min
- array of min values. (accepts Float.NEGATIVE_INFINITY
)max
- array of max values. (accepts Float.MAX_VALUE
)java.lang.IllegalArgumentException
- if field
is null, min
or max
is invalidpublic static Query newContainsQuery(java.lang.String field, float[] min, float[] max)
field
- field name. must not be null.min
- array of min values. (accepts Float.NEGATIVE_INFINITY
)max
- array of max values. (accepts Float.POSITIVE_INFINITY
)java.lang.IllegalArgumentException
- if field
is null, min
or max
is invalidpublic static Query newWithinQuery(java.lang.String field, float[] min, float[] max)
field
- field name. must not be null.min
- array of min values. (accepts Float.NEGATIVE_INFINITY
)max
- array of max values. (accepts Float.POSITIVE_INFINITY
)java.lang.IllegalArgumentException
- if field
is null, min
or max
is invalidpublic static Query newCrossesQuery(java.lang.String field, float[] min, float[] max)
field
- field name. must not be null.min
- array of min values. (accepts Float.NEGATIVE_INFINITY
)max
- array of max values. (accepts Float.POSITIVE_INFINITY
)java.lang.IllegalArgumentException
- if field
is null, min
or max
is invalidprivate static Query newRelationQuery(java.lang.String field, float[] min, float[] max, RangeFieldQuery.QueryType relation)
public java.lang.String toString()
Field
private static java.lang.String toString(byte[] ranges, int dimension)
ranges
- the encoded ranges, never nulldimension
- the dimension of interest