Package org.apache.lucene.document
Class LongField
java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.LongField
- All Implemented Interfaces:
IndexableField
Field that stores a per-document
long
value for scoring, sorting or value retrieval
and index the field for fast range filters. If you need more fine-grained control you can use
LongPoint
, NumericDocValuesField
or SortedNumericDocValuesField
, and
StoredField
.
This field defines static factory methods for creating common queries:
newExactQuery(String, long)
for matching an exact 1D point.newRangeQuery(String, long, long)
for matching a 1D range.newSetQuery(String, long...)
for matching a 1D set.
- See Also:
-
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, type
-
Constructor Summary
ConstructorsConstructorDescriptionLongField
(String name, long value, Field.Store stored) Creates a new LongField, indexing the provided point, storing it as a DocValue, and optionally storing it as a stored field. -
Method Summary
Modifier and TypeMethodDescriptionNon-null if this field has a binary valuestatic Query
newDistanceFeatureQuery
(String field, float weight, long origin, long pivotDistance) Returns a query that scores documents based on their distance toorigin
: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 long values.static Query
newSetQuery
(String field, long... values) Create a query matching values in a supplied setstatic SortField
newSortField
(String field, boolean reverse, SortedNumericSelector.Type selector) Create a newSortField
for long values.void
setLongValue
(long value) Expert: change the value of this field.Stored value.toString()
Prints a Field for human consumption.Methods inherited from class org.apache.lucene.document.Field
fieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
-
Constructor Details
-
LongField
Creates a new LongField, indexing the provided point, storing it as a DocValue, and optionally storing it as a stored field.- Parameters:
name
- field namevalue
- the long valuestored
- whether to store the field- Throws:
IllegalArgumentException
- if the field name or value is null.
-
-
Method Details
-
binaryValue
Description copied from interface:IndexableField
Non-null if this field has a binary value- Specified by:
binaryValue
in interfaceIndexableField
- Overrides:
binaryValue
in classField
-
storedValue
Description copied from interface:IndexableField
Stored value. This method is called to populate stored fields and must return a non-null value if the field stored.- Specified by:
storedValue
in interfaceIndexableField
- Overrides:
storedValue
in classField
-
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
-
toString
Description copied from class:Field
Prints a Field for human consumption. -
newExactQuery
Create a query for matching an exact long value.- 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
Create a range query for long values.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.
-
newSetQuery
Create a query matching values in a supplied set- Parameters:
field
- field name. must not benull
.values
- long values- Returns:
- a query matching documents within this set.
- Throws:
IllegalArgumentException
- iffield
is null.
-
newSortField
public static SortField newSortField(String field, boolean reverse, SortedNumericSelector.Type selector) Create a newSortField
for long values.- Parameters:
field
- field name. must not benull
.reverse
- true if natural order should be reversed.selector
- custom selector type for choosing the sort value from the set.
-
newDistanceFeatureQuery
public static Query newDistanceFeatureQuery(String field, float weight, long origin, long pivotDistance) 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
.
-