Class FloatPoint
- java.lang.Object
-
- org.apache.lucene.document.Field
-
- org.apache.lucene.document.FloatPoint
-
- All Implemented Interfaces:
IndexableField
public final class FloatPoint extends Field
An indexedfloat
field for fast range filters. If you also need to store the value, you should add a separateStoredField
instance.Finding all documents within an N-dimensional at search time is efficient. Multiple values for the same field in one document is allowed.
This field defines static factory methods for creating common queries:
newExactQuery(String, float)
for matching an exact 1D point.newSetQuery(String, float...)
for matching a set of 1D values.newRangeQuery(String, float, float)
for matching a 1D range.newRangeQuery(String, float[], float[])
for matching points/ranges in n-dimensional space.
- See Also:
PointValues
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.document.Field
fieldsData, name, tokenStream, type
-
-
Constructor Summary
Constructors Constructor Description FloatPoint(String name, float... point)
Creates a new FloatPoint, indexing the provided N-dimensional float point.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static float
decodeDimension(byte[] value, int offset)
Decode single float dimensionstatic void
encodeDimension(float value, byte[] dest, int offset)
Encode single float dimensionstatic Query
newExactQuery(String field, float value)
Create a query for matching an exact float value.static Query
newRangeQuery(String field, float[] lowerValue, float[] upperValue)
Create a range query for n-dimensional float values.static Query
newRangeQuery(String field, float lowerValue, float upperValue)
Create a range query for float values.static Query
newSetQuery(String field, float... values)
Create a query matching any of the specified 1D values.static Query
newSetQuery(String field, Collection<Float> values)
Create a query matching any of the specified 1D values.static float
nextDown(float f)
Return the greatest float that compares less thanf
consistently withFloat.compare(float, float)
.static float
nextUp(float f)
Return the least float that compares greater thanf
consistently withFloat.compare(float, float)
.Number
numericValue()
Non-null if this field has a numeric valuestatic BytesRef
pack(float... point)
Pack a float point into a BytesRefvoid
setBytesValue(BytesRef bytes)
Expert: change the value of this field.void
setFloatValue(float value)
Expert: change the value of this field.void
setFloatValues(float... point)
Change the values of this fieldString
toString()
Prints a Field for human consumption.-
Methods inherited from class org.apache.lucene.document.Field
binaryValue, fieldType, getCharSequenceValue, invertableType, name, readerValue, setBytesValue, setByteValue, setDoubleValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, storedValue, stringValue, tokenStream, tokenStreamValue
-
-
-
-
Constructor Detail
-
FloatPoint
public FloatPoint(String name, float... point)
Creates a new FloatPoint, indexing the provided N-dimensional float point.- Parameters:
name
- field namepoint
- float[] value- Throws:
IllegalArgumentException
- if the field name or value is null.
-
-
Method Detail
-
nextUp
public static float nextUp(float f)
Return the least float that compares greater thanf
consistently withFloat.compare(float, float)
. The only difference withMath.nextUp(float)
is that this method returns+0f
when the argument is-0f
.
-
nextDown
public static float nextDown(float f)
Return the greatest float that compares less thanf
consistently withFloat.compare(float, float)
. The only difference withMath.nextDown(float)
is that this method returns-0f
when the argument is+0f
.
-
setFloatValue
public void setFloatValue(float value)
Description copied from class:Field
Expert: change the value of this field. SeeField.setStringValue(String)
.- Overrides:
setFloatValue
in classField
-
setFloatValues
public void setFloatValues(float... point)
Change the values of this field
-
setBytesValue
public void setBytesValue(BytesRef bytes)
Description copied from class:Field
Expert: change the value of this field. SeeField.setStringValue(String)
.NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
- Overrides:
setBytesValue
in classField
-
numericValue
public Number numericValue()
Description copied from interface:IndexableField
Non-null if this field has a numeric value- Specified by:
numericValue
in interfaceIndexableField
- Overrides:
numericValue
in classField
-
pack
public static BytesRef pack(float... point)
Pack a float point into a BytesRef- Parameters:
point
- float[] value- Throws:
IllegalArgumentException
- is the value is null or of zero length
-
toString
public String toString()
Description copied from class:Field
Prints a Field for human consumption.
-
encodeDimension
public static void encodeDimension(float value, byte[] dest, int offset)
Encode single float dimension
-
decodeDimension
public static float decodeDimension(byte[] value, int offset)
Decode single float dimension
-
newExactQuery
public static Query newExactQuery(String field, float value)
Create a query for matching an exact float value.This is for simple one-dimension points, for multidimensional points use
newRangeQuery(String, float[], float[])
instead.- Parameters:
field
- field name. must not benull
.value
- float value- Returns:
- a query matching documents with this exact value
- Throws:
IllegalArgumentException
- iffield
is null.
-
newRangeQuery
public static Query newRangeQuery(String field, float lowerValue, float upperValue)
Create a range query for float values.This is for simple one-dimension ranges, for multidimensional ranges use
newRangeQuery(String, float[], float[])
instead.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting
lowerValue = Float.NEGATIVE_INFINITY
orupperValue = Float.POSITIVE_INFINITY
.Ranges are inclusive. For exclusive ranges, pass
nextUp(lowerValue)
ornextDown(upperValue)
.Range comparisons are consistent with
Float.compareTo(Float)
.- Parameters:
field
- field name. must not benull
.lowerValue
- lower portion of the range (inclusive).upperValue
- upper portion of the range (inclusive).- Returns:
- a query matching documents within this range.
- Throws:
IllegalArgumentException
- iffield
is null.
-
newRangeQuery
public static Query newRangeQuery(String field, float[] lowerValue, float[] upperValue)
Create a range query for n-dimensional float values.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting
lowerValue[i] = Float.NEGATIVE_INFINITY
orupperValue[i] = Float.POSITIVE_INFINITY
.Ranges are inclusive. For exclusive ranges, pass
Math#nextUp(lowerValue[i])
orMath.nextDown(upperValue[i])
.Range comparisons are consistent with
Float.compareTo(Float)
.- Parameters:
field
- field name. must not benull
.lowerValue
- lower portion of the range (inclusive). must not benull
.upperValue
- upper portion of the range (inclusive). must not benull
.- Returns:
- a query matching documents within this range.
- Throws:
IllegalArgumentException
- iffield
is null, iflowerValue
is null, ifupperValue
is null, or iflowerValue.length != upperValue.length
-
newSetQuery
public static Query newSetQuery(String field, float... values)
Create a query matching any of the specified 1D values. This is the points equivalent ofTermsQuery
.- Parameters:
field
- field name. must not benull
.values
- all values to match
-
newSetQuery
public static Query newSetQuery(String field, Collection<Float> values)
Create a query matching any of the specified 1D values. This is the points equivalent ofTermsQuery
.- Parameters:
field
- field name. must not benull
.values
- all values to match
-
-