Class LongPoint
- java.lang.Object
-
- org.apache.lucene.document.Field
-
- org.apache.lucene.document.LongPoint
-
- All Implemented Interfaces:
IndexableField
public final class LongPoint extends Field
An indexedlong
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 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.
- 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static long
decodeDimension(byte[] value, int offset)
Decode single long dimensionstatic void
encodeDimension(long value, byte[] dest, int offset)
Encode single long dimensionstatic Query
newDistanceFeatureQuery(String field, float weight, long origin, long pivotDistance)
Deprecated.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, long... values)
Create a query matching any of the specified 1D values.static Query
newSetQuery(String field, Collection<Long> values)
Create a query matching any of the specified 1D values.Number
numericValue()
Non-null if this field has a numeric valuestatic BytesRef
pack(long... point)
Pack a long point into a BytesRefvoid
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 fieldString
toString()
Prints a Field for human consumption.static void
unpack(BytesRef bytesRef, int start, long[] buf)
Unpack a BytesRef into a long point.-
Methods inherited from class org.apache.lucene.document.Field
binaryValue, fieldType, getCharSequenceValue, invertableType, name, readerValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setReaderValue, setShortValue, setStringValue, setTokenStream, storedValue, stringValue, tokenStream, tokenStreamValue
-
-
-
-
Constructor Detail
-
LongPoint
public LongPoint(String name, long... point)
Creates a new LongPoint, indexing the provided N-dimensional long point.- Parameters:
name
- field namepoint
- long[] value- Throws:
IllegalArgumentException
- if the field name or value is null.
-
-
Method Detail
-
setLongValue
public void setLongValue(long value)
Description copied from class:Field
Expert: change the value of this field. SeeField.setStringValue(String)
.- Overrides:
setLongValue
in classField
-
setLongValues
public void setLongValues(long... 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(long... point)
Pack a long point into a BytesRef- Parameters:
point
- long[] value- Throws:
IllegalArgumentException
- is the value is null or of zero length
-
unpack
public static void unpack(BytesRef bytesRef, int start, long[] buf)
Unpack a BytesRef into a long point. This method can be used to unpack values that were packed withpack(long...)
.- Parameters:
bytesRef
- BytesRef Valuestart
- the start offset to unpack the values frombuf
- the buffer to store the values in- Throws:
IllegalArgumentException
- if bytesRef or buf are null
-
toString
public String toString()
Description copied from class:Field
Prints a Field for human consumption.
-
encodeDimension
public static void encodeDimension(long value, byte[] dest, int offset)
Encode single long dimension
-
decodeDimension
public static long decodeDimension(byte[] value, int offset)
Decode single long dimension
-
newExactQuery
public static Query newExactQuery(String field, long value)
Create a query for matching an exact long value.This is for simple one-dimension points, for multidimensional points use
newRangeQuery(String, long[], long[])
instead.- Parameters:
field
- field name. must not benull
.value
- exact value- Returns:
- a query matching documents with this exact value
- Throws:
IllegalArgumentException
- iffield
is null.
-
newRangeQuery
public static Query newRangeQuery(String field, long lowerValue, long upperValue)
Create a range query for long values.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
orupperValue = Long.MAX_VALUE
.Ranges are inclusive. For exclusive ranges, pass
Math.addExact(lowerValue, 1)
orMath.addExact(upperValue, -1)
.- 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, long[] lowerValue, long[] upperValue)
Create a range query for n-dimensional long values.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting
lowerValue[i] = Long.MIN_VALUE
orupperValue[i] = Long.MAX_VALUE
.Ranges are inclusive. For exclusive ranges, pass
Math.addExact(lowerValue[i], 1)
orMath.addExact(upperValue[i], -1)
.- 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, long... 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<Long> 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
-
newDistanceFeatureQuery
@Deprecated public static Query newDistanceFeatureQuery(String field, float weight, long origin, long pivotDistance)
Deprecated.Given a field that indexes the same long values into aLongPoint
and doc values (eitherNumericDocValuesField
orSortedNumericDocValuesField
), this returns a query that scores documents based on their distance toorigin
:score = weight * pivotDistance / (pivotDistance + distance)
, ie. score is in the[0, weight]
range, is equal toweight
when the document's value is equal toorigin
and is equal toweight/2
when the document's value is distant ofpivotDistance
fromorigin
. In case of multi-valued fields, only the closest point toorigin
will be considered. This query is typically useful to boost results based on recency by adding this query to aBooleanClause.Occur.SHOULD
clause of aBooleanQuery
. @Deprecated UseLongField.newDistanceFeatureQuery(java.lang.String, float, long, long)
-
-