public final class LongPoint extends Field
long
field for fast range filters. If you also
need to store the value, you should add a separate StoredField
instance.
Finding all documents within an N-dimensional shape or range 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, long)
for matching an exact 1D point.
newSetQuery(String, long...)
for matching a set of 1D values.
newRangeQuery(String, long, long)
for matching a 1D range.
newRangeQuery(String, long[], long[])
for matching points/ranges in n-dimensional space.
PointValues
Field.Store
fieldsData, name, tokenStream, type
Constructor and Description |
---|
LongPoint(String name,
long... point)
Creates a new LongPoint, indexing the
provided N-dimensional long point.
|
Modifier and Type | Method and Description |
---|---|
static long |
decodeDimension(byte[] value,
int offset)
Decode single long dimension
|
static void |
encodeDimension(long value,
byte[] dest,
int offset)
Encode single long dimension
|
static Query |
newDistanceFeatureQuery(String field,
float weight,
long origin,
long pivotDistance)
Given a field that indexes the same long values into a
LongPoint
and doc values (either NumericDocValuesField or
SortedNumericDocValuesField ), this returns a query that scores
documents based on their distance to origin :
score = weight * pivotDistance / (pivotDistance + distance) , ie. |
static Query |
newExactQuery(String field,
long value)
Create a query for matching an exact long value.
|
static Query |
newRangeQuery(String field,
long[] lowerValue,
long[] upperValue)
Create a range query for n-dimensional long values.
|
static Query |
newRangeQuery(String field,
long lowerValue,
long upperValue)
Create a range query for long values.
|
static Query |
newSetQuery(String field,
Collection<Long> values)
Create a query matching any of the specified 1D values.
|
static Query |
newSetQuery(String field,
long... values)
Create a query matching any of the specified 1D values.
|
Number |
numericValue()
Non-null if this field has a numeric value
|
static BytesRef |
pack(long... point)
Pack a long point into a BytesRef
|
void |
setBytesValue(BytesRef bytes)
Expert: change the value of this field.
|
void |
setLongValue(long value)
Expert: change the value of this field.
|
void |
setLongValues(long... point)
Change the values of this field
|
String |
toString()
Prints a Field for human consumption.
|
binaryValue, fieldType, getCharSequenceValue, name, readerValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
public LongPoint(String name, long... point)
name
- field namepoint
- long[] valueIllegalArgumentException
- if the field name or value is null.public void setLongValue(long value)
Field
Field.setStringValue(String)
.setLongValue
in class Field
public void setLongValues(long... point)
public void setBytesValue(BytesRef bytes)
Field
Field.setStringValue(String)
.
NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
setBytesValue
in class Field
public Number numericValue()
IndexableField
numericValue
in interface IndexableField
numericValue
in class Field
public static BytesRef pack(long... point)
point
- long[] valueIllegalArgumentException
- is the value is null or of zero lengthpublic String toString()
Field
public static void encodeDimension(long value, byte[] dest, int offset)
public static long decodeDimension(byte[] value, int offset)
public static Query newExactQuery(String field, long value)
This is for simple one-dimension points, for multidimensional points use
newRangeQuery(String, long[], long[])
instead.
field
- field name. must not be null
.value
- exact valueIllegalArgumentException
- if field
is null.public static Query newRangeQuery(String field, long lowerValue, long upperValue)
This is for simple one-dimension ranges, for multidimensional ranges use
newRangeQuery(String, long[], long[])
instead.
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting lowerValue = Long.MIN_VALUE
or upperValue = Long.MAX_VALUE
.
Ranges are inclusive. For exclusive ranges, pass Math.addExact(lowerValue, 1)
or Math.addExact(upperValue, -1)
.
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, long[] lowerValue, long[] upperValue)
You can have half-open ranges (which are in fact </≤ or >/≥ queries)
by setting lowerValue[i] = Long.MIN_VALUE
or upperValue[i] = Long.MAX_VALUE
.
Ranges are inclusive. For exclusive ranges, pass Math.addExact(lowerValue[i], 1)
or Math.addExact(upperValue[i], -1)
.
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, long... values)
TermsQuery
.field
- field name. must not be null
.values
- all values to matchpublic static Query newSetQuery(String field, Collection<Long> values)
TermsQuery
.field
- field name. must not be null
.values
- all values to matchpublic static Query newDistanceFeatureQuery(String field, float weight, long origin, long pivotDistance)
LongPoint
and doc values (either NumericDocValuesField
or
SortedNumericDocValuesField
), this returns a query that scores
documents based on their distance to origin
:
score = weight * pivotDistance / (pivotDistance + distance)
, ie.
score is in the [0, weight]
range, is equal to weight
when
the document's value is equal to origin
and is equal to
weight/2
when the document's value is distant of
pivotDistance
from origin
.
In case of multi-valued fields, only the closest point to origin
will be considered.
This query is typically useful to boost results based on recency by adding
this query to a BooleanClause.Occur.SHOULD
clause of a BooleanQuery
.Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.