Package org.apache.lucene.document
Class LongField
- java.lang.Object
- 
- org.apache.lucene.document.Field
- 
- org.apache.lucene.document.LongField
 
 
- 
- All Implemented Interfaces:
- IndexableField
 
 public final class LongField extends Field Field that stores a per-documentlongvalue for scoring, sorting or value retrieval and index the field for fast range filters. If you need more fine-grained control you can useLongPoint,NumericDocValuesFieldorSortedNumericDocValuesField, andStoredField.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:
- PointValues
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.apache.lucene.document.FieldField.Store
 
- 
 - 
Field Summary- 
Fields inherited from class org.apache.lucene.document.FieldfieldsData, name, tokenStream, type
 
- 
 - 
Constructor SummaryConstructors Constructor Description LongField(String name, long value)Deprecated.UseLongField(String, long, Field.Store)withField.Store.NOinstead.LongField(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 SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BytesRefbinaryValue()Non-null if this field has a binary valuestatic QuerynewDistanceFeatureQuery(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 QuerynewExactQuery(String field, long value)Create a query for matching an exact long value.static QuerynewRangeQuery(String field, long lowerValue, long upperValue)Create a range query for long values.static QuerynewSetQuery(String field, long... values)Create a query matching values in a supplied setstatic SortFieldnewSortField(String field, boolean reverse, SortedNumericSelector.Type selector)Create a newSortFieldfor long values.voidsetLongValue(long value)Expert: change the value of this field.StoredValuestoredValue()Stored value.StringtoString()Prints a Field for human consumption.- 
Methods inherited from class org.apache.lucene.document.FieldfieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
 
- 
 
- 
- 
- 
Constructor Detail- 
LongField@Deprecated public LongField(String name, long value) Deprecated.UseLongField(String, long, Field.Store)withField.Store.NOinstead.Creates a new LongField, indexing the provided point and storing it as a DocValue- Parameters:
- name- field name
- value- the long value
- Throws:
- IllegalArgumentException- if the field name or value is null.
 
 - 
LongFieldpublic LongField(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.- Parameters:
- name- field name
- value- the long value
- stored- whether to store the field
- Throws:
- IllegalArgumentException- if the field name or value is null.
 
 
- 
 - 
Method Detail- 
binaryValuepublic BytesRef binaryValue() Description copied from interface:IndexableFieldNon-null if this field has a binary value- Specified by:
- binaryValuein interface- IndexableField
- Overrides:
- binaryValuein class- Field
 
 - 
storedValuepublic StoredValue storedValue() Description copied from interface:IndexableFieldStored value. This method is called to populate stored fields and must return a non-null value if the field stored.- Specified by:
- storedValuein interface- IndexableField
- Overrides:
- storedValuein class- Field
 
 - 
setLongValuepublic void setLongValue(long value) Description copied from class:FieldExpert: change the value of this field. SeeField.setStringValue(String).- Overrides:
- setLongValuein class- Field
 
 - 
toStringpublic String toString() Description copied from class:FieldPrints a Field for human consumption.
 - 
newExactQuerypublic static Query newExactQuery(String field, long value) Create a query for matching an exact long value.- Parameters:
- field- field name. must not be- null.
- value- exact value
- Returns:
- a query matching documents with this exact value
- Throws:
- IllegalArgumentException- if- fieldis null.
 
 - 
newRangeQuerypublic static Query newRangeQuery(String field, long lowerValue, long upperValue) Create a range query for long values.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting lowerValue = Long.MIN_VALUEorupperValue = Long.MAX_VALUE.Ranges are inclusive. For exclusive ranges, pass Math.addExact(lowerValue, 1)orMath.addExact(upperValue, -1).- Parameters:
- field- field name. must not be- null.
- lowerValue- lower portion of the range (inclusive).
- upperValue- upper portion of the range (inclusive).
- Returns:
- a query matching documents within this range.
- Throws:
- IllegalArgumentException- if- fieldis null.
 
 - 
newSetQuerypublic static Query newSetQuery(String field, long... values) Create a query matching values in a supplied set- Parameters:
- field- field name. must not be- null.
- values- long values
- Returns:
- a query matching documents within this set.
- Throws:
- IllegalArgumentException- if- fieldis null.
 
 - 
newSortFieldpublic static SortField newSortField(String field, boolean reverse, SortedNumericSelector.Type selector) Create a newSortFieldfor long values.- Parameters:
- field- field name. must not be- null.
- reverse- true if natural order should be reversed.
- selector- custom selector type for choosing the sort value from the set.
 
 - 
newDistanceFeatureQuerypublic 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 toweightwhen the document's value is equal tooriginand is equal toweight/2when the document's value is distant ofpivotDistancefromorigin. In case of multi-valued fields, only the closest point tooriginwill be considered. This query is typically useful to boost results based on recency by adding this query to aBooleanClause.Occur.SHOULDclause of aBooleanQuery.
 
- 
 
-