public final class HalfFloatPoint extends Field
half-float
field for fast range filters. If you also
need to store the value, you should add a separate StoredField
instance.
If you need doc values, you can store them in a NumericDocValuesField
and use halfFloatToSortableShort(float)
and
sortableShortToHalfFloat(short)
for encoding/decoding.
The API takes floats, but they will be encoded to half-floats before being indexed. In case the provided floats cannot be represented accurately as a half float, they will be rounded to the closest value that can be represented as a half float. In case of tie, values will be rounded to the value that has a zero as its least significant bit.
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.
PointValues
Field.Store
Modifier and Type | Field and Description |
---|---|
static int |
BYTES
The number of bytes used to represent a half-float value.
|
fieldsData, name, tokenStream, type
Constructor and Description |
---|
HalfFloatPoint(String name,
float... point)
Creates a new FloatPoint, indexing the
provided N-dimensional float point.
|
Modifier and Type | Method and Description |
---|---|
static float |
decodeDimension(byte[] value,
int offset)
Decode single float dimension
|
static void |
encodeDimension(float value,
byte[] dest,
int offset)
Encode single float dimension
|
static short |
halfFloatToSortableShort(float v)
Convert a half-float to a short value that maintains ordering.
|
static Query |
newExactQuery(String field,
float value)
Create a query for matching an exact half-float value.
|
static Query |
newRangeQuery(String field,
float[] lowerValue,
float[] upperValue)
Create a range query for n-dimensional half-float values.
|
static Query |
newRangeQuery(String field,
float lowerValue,
float upperValue)
Create a range query for half-float values.
|
static Query |
newSetQuery(String field,
Collection<Float> values)
Create a query matching any of the specified 1D values.
|
static Query |
newSetQuery(String field,
float... values)
Create a query matching any of the specified 1D values.
|
static float |
nextDown(float v)
Return the first half float which is immediately smaller than
v . |
static float |
nextUp(float v)
Return the first half float which is immediately greater than
v . |
Number |
numericValue() |
void |
setBytesValue(BytesRef bytes) |
void |
setFloatValue(float value) |
void |
setFloatValues(float... point)
Change the values of this field
|
static float |
sortableShortToHalfFloat(short bits)
Convert short bits to a half-float value that maintains ordering.
|
String |
toString() |
binaryValue, fieldType, name, readerValue, setBytesValue, setByteValue, setDoubleValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
public static final int BYTES
public HalfFloatPoint(String name, float... point)
name
- field namepoint
- float[] valueIllegalArgumentException
- if the field name or value is null.public static float nextUp(float v)
v
.
If the argument is Float.NaN
then the return value is
Float.NaN
. If the argument is Float.POSITIVE_INFINITY
then the return value is Float.POSITIVE_INFINITY
.public static float nextDown(float v)
v
.
If the argument is Float.NaN
then the return value is
Float.NaN
. If the argument is Float.NEGATIVE_INFINITY
then the return value is Float.NEGATIVE_INFINITY
.public static short halfFloatToSortableShort(float v)
public static float sortableShortToHalfFloat(short bits)
public void setFloatValue(float value)
setFloatValue
in class Field
public void setFloatValues(float... point)
public void setBytesValue(BytesRef bytes)
setBytesValue
in class Field
public Number numericValue()
numericValue
in interface IndexableField
numericValue
in class Field
public static void encodeDimension(float value, byte[] dest, int offset)
public static float decodeDimension(byte[] value, int offset)
public static Query newExactQuery(String field, float value)
value
cannot be represented accurately
as a half-float.
This is for simple one-dimension points, for multidimensional points use
newRangeQuery(String, float[], float[])
instead.
field
- field name. must not be null
.value
- half-float valueIllegalArgumentException
- if field
is null.public static Query newRangeQuery(String field, float lowerValue, float upperValue)
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
or upperValue = Float.POSITIVE_INFINITY
.
Ranges are inclusive. For exclusive ranges, pass nextUp(lowerValue)
or nextDown(upperValue)
.
Range comparisons are consistent with Float.compareTo(Float)
.
field
- field name. must not be null
.lowerValue
- lower portion of the range (inclusive).upperValue
- upper portion of the range (inclusive).IllegalArgumentException
- if field
is null.public static Query newRangeQuery(String field, float[] lowerValue, float[] upperValue)
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting lowerValue[i] = Float.NEGATIVE_INFINITY
or upperValue[i] = Float.POSITIVE_INFINITY
.
Ranges are inclusive. For exclusive ranges, pass nextUp(lowerValue[i])
or nextDown(upperValue[i])
.
Range comparisons are consistent with Float.compareTo(Float)
.
field
- field name. must not be null
.lowerValue
- lower portion of the range (inclusive). must not be null
.upperValue
- upper portion of the range (inclusive). must not be null
.IllegalArgumentException
- if field
is null, if lowerValue
is null, if upperValue
is null,
or if lowerValue.length != upperValue.length
public static Query newSetQuery(String field, float... values)
TermsQuery
.
Values will be rounded to the closest half-float if they
cannot be represented accurately as a half-float.field
- field name. must not be null
.values
- all values to matchpublic static Query newSetQuery(String field, Collection<Float> values)
TermsQuery
.field
- field name. must not be null
.values
- all values to matchCopyright © 2000-2018 Apache Software Foundation. All Rights Reserved.