java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.FloatRange
- All Implemented Interfaces:
IndexableField
An indexed Float 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 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstores float values so number of bytes is 4Fields inherited from class org.apache.lucene.document.Field
fieldsData, name, tokenStream, type -
Constructor Summary
ConstructorsConstructorDescriptionFloatRange(String name, float[] min, float[] max) Create a new FloatRange type, from min/max parallel arrays -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckArgs(float[] min, float[] max) validate the arguments(package private) static floatdecodeMax(byte[] b, int dimension) decodes the max value (for the defined dimension) from the encoded input byte array(package private) static floatdecodeMin(byte[] b, int dimension) decodes the min value (for the defined dimension) from the encoded input byte array(package private) static byte[]encode(float[] min, float[] max) Encodes the min, max ranges into a byte arrayprivate static voidencode(float val, byte[] bytes, int offset) encode the given value into the byte array at the defined offsetfloatgetMax(int dimension) Get the max value for the given dimensionfloatgetMin(int dimension) Get the min value for the given dimensionprivate static FieldTypegetType(int dimensions) set the field typestatic QuerynewContainsQuery(String field, float[] min, float[] max) Create a query for matching indexed float ranges that contain the defined range.static QuerynewCrossesQuery(String field, float[] min, float[] max) Create a query for matching indexed ranges that cross the defined range.static QuerynewIntersectsQuery(String field, float[] min, float[] max) Create a query for matching indexed ranges that intersect the defined range.private static QuerynewRelationQuery(String field, float[] min, float[] max, RangeFieldQuery.QueryType relation) helper method for creating the desired relational querystatic QuerynewWithinQuery(String field, float[] min, float[] max) Create a query for matching indexed ranges that are within the defined range.voidsetRangeValues(float[] min, float[] max) Changes the values of the field.toString()Prints a Field for human consumption.private static StringtoString(byte[] ranges, int dimension) Returns the String representation for the range at the given dimension(package private) static voidverifyAndEncode(float[] min, float[] max, byte[] bytes) encode the ranges into a sortable byte array (Float.NaNnot allowed)Methods inherited from class org.apache.lucene.document.Field
binaryValue, fieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, storedValue, stringValue, tokenStream, tokenStreamValue
-
Field Details
-
BYTES
public static final int BYTESstores float values so number of bytes is 4- See Also:
-
-
Constructor Details
-
FloatRange
Create a new FloatRange 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 dimensionmax- range max values; each entry is the max value for the dimension
-
-
Method Details
-
getType
set the field type -
setRangeValues
public void setRangeValues(float[] min, float[] max) Changes the values of the field.- Parameters:
min- array of min values. (acceptsFloat.NEGATIVE_INFINITY)max- array of max values. (acceptsFloat.POSITIVE_INFINITY)- Throws:
IllegalArgumentException- ifminormaxis invalid
-
checkArgs
private static void checkArgs(float[] min, float[] max) validate the arguments -
encode
static byte[] encode(float[] min, float[] max) Encodes the min, max ranges into a byte array -
verifyAndEncode
static void verifyAndEncode(float[] min, float[] max, byte[] bytes) encode the ranges into a sortable byte array (Float.NaNnot allowed)example for 4 dimensions (8 bytes per dimension value): minD1 ... minD4 | maxD1 ... maxD4
-
encode
private static void encode(float val, byte[] bytes, int offset) encode the given value into the byte array at the defined offset -
getMin
public float getMin(int dimension) Get the min value for the given dimension- Parameters:
dimension- the dimension, always positive- Returns:
- the decoded min value
-
getMax
public float getMax(int dimension) Get the max value for the given dimension- Parameters:
dimension- the dimension, always positive- Returns:
- the decoded max value
-
decodeMin
static float decodeMin(byte[] b, int dimension) decodes the min value (for the defined dimension) from the encoded input byte array -
decodeMax
static float decodeMax(byte[] b, int dimension) decodes the max value (for the defined dimension) from the encoded input byte array -
newIntersectsQuery
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. (acceptsFloat.NEGATIVE_INFINITY)max- array of max values. (acceptsFloat.MAX_VALUE)- Returns:
- query for matching intersecting ranges (overlap, within, or contains)
- Throws:
IllegalArgumentException- iffieldis null,minormaxis invalid
-
newContainsQuery
Create a query for matching indexed float ranges that contain the defined range.- Parameters:
field- field name. must not be null.min- array of min values. (acceptsFloat.NEGATIVE_INFINITY)max- array of max values. (acceptsFloat.POSITIVE_INFINITY)- Returns:
- query for matching ranges that contain the defined range
- Throws:
IllegalArgumentException- iffieldis null,minormaxis invalid
-
newWithinQuery
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. (acceptsFloat.NEGATIVE_INFINITY)max- array of max values. (acceptsFloat.POSITIVE_INFINITY)- Returns:
- query for matching ranges within the defined range
- Throws:
IllegalArgumentException- iffieldis null,minormaxis invalid
-
newCrossesQuery
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. (acceptsFloat.NEGATIVE_INFINITY)max- array of max values. (acceptsFloat.POSITIVE_INFINITY)- Returns:
- query for matching ranges within the defined range
- Throws:
IllegalArgumentException- iffieldis null,minormaxis invalid
-
newRelationQuery
private static Query newRelationQuery(String field, float[] min, float[] max, RangeFieldQuery.QueryType relation) helper method for creating the desired relational query -
toString
Description copied from class:FieldPrints a Field for human consumption. -
toString
Returns the String representation for the range at the given dimension- Parameters:
ranges- the encoded ranges, never nulldimension- the dimension of interest- Returns:
- The string representation for the range at the provided dimension
-