Class LegacyNumericTokenStream
- All Implemented Interfaces:
Closeable,AutoCloseable
TokenStream for indexing numeric values that can be
used by LegacyNumericRangeQuery.
Note that for simple usage, LegacyIntField, LegacyLongField, LegacyFloatField or
LegacyDoubleField is recommended. These fields disable norms and
term freqs, as they are not usually needed during searching. If you need to change these
settings, you should use this class.
Here's an example usage, for an int field:
FieldType fieldType = new FieldType(TextField.TYPE_NOT_STORED); fieldType.setOmitNorms(true); fieldType.setIndexOptions(IndexOptions.DOCS_ONLY); Field field = new Field(name, new LegacyNumericTokenStream(precisionStep).setIntValue(value), fieldType); document.add(field);
For optimal performance, re-use the TokenStream and Field instance for more than one document:
LegacyNumericTokenStream stream = new LegacyNumericTokenStream(precisionStep);
FieldType fieldType = new FieldType(TextField.TYPE_NOT_STORED);
fieldType.setOmitNorms(true);
fieldType.setIndexOptions(IndexOptions.DOCS_ONLY);
Field field = new Field(name, stream, fieldType);
Document document = new Document();
document.add(field);
for(all documents) {
stream.setIntValue(value)
writer.addDocument(document);
}
This stream is not intended to be used in analyzers; it's more for iterating the different precisions during indexing a specific numeric value.
NOTE: as token streams are only consumed once the document is added to the index, if
you index more than one numeric field, use a separate LegacyNumericTokenStream
instance for each.
See LegacyNumericRangeQuery for more details on the precisionStep parameter as
well as how numeric fields work under the hood.
- Since:
- 2.9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Expert: Use this attribute to get the details of the currently generated token.static final classDeprecated.Implementation ofLegacyNumericTokenStream.LegacyNumericTermAttribute.Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
org.apache.lucene.util.AttributeSource.State -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.The full precision token gets this token type assigned.static final StringDeprecated.The lower precision tokens gets this token type assigned.Fields inherited from class org.apache.lucene.analysis.TokenStream
DEFAULT_TOKEN_ATTRIBUTE_FACTORY -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Creates a token stream for numeric values using the defaultprecisionStepLegacyNumericUtils.PRECISION_STEP_DEFAULT(16).LegacyNumericTokenStream(int precisionStep) Deprecated.Creates a token stream for numeric values with the specifiedprecisionStep.LegacyNumericTokenStream(org.apache.lucene.util.AttributeFactory factory, int precisionStep) Deprecated.Expert: Creates a token stream for numeric values with the specifiedprecisionStepusing the givenAttributeFactory. -
Method Summary
Modifier and TypeMethodDescriptionintDeprecated.Returns the precision step.booleanDeprecated.voidreset()Deprecated.setDoubleValue(double value) Deprecated.Initializes the token stream with the supplieddoublevalue.setFloatValue(float value) Deprecated.Initializes the token stream with the suppliedfloatvalue.setIntValue(int value) Deprecated.Initializes the token stream with the suppliedintvalue.setLongValue(long value) Deprecated.Initializes the token stream with the suppliedlongvalue.toString()Deprecated.Methods inherited from class org.apache.lucene.analysis.TokenStream
close, endMethods inherited from class org.apache.lucene.util.AttributeSource
addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState
-
Field Details
-
TOKEN_TYPE_FULL_PREC
Deprecated.The full precision token gets this token type assigned.- See Also:
-
TOKEN_TYPE_LOWER_PREC
Deprecated.The lower precision tokens gets this token type assigned.- See Also:
-
-
Constructor Details
-
LegacyNumericTokenStream
public LegacyNumericTokenStream()Deprecated.Creates a token stream for numeric values using the defaultprecisionStepLegacyNumericUtils.PRECISION_STEP_DEFAULT(16). The stream is not yet initialized, before using set a value using the various set???Value() methods. -
LegacyNumericTokenStream
public LegacyNumericTokenStream(int precisionStep) Deprecated.Creates a token stream for numeric values with the specifiedprecisionStep. The stream is not yet initialized, before using set a value using the various set???Value() methods. -
LegacyNumericTokenStream
public LegacyNumericTokenStream(org.apache.lucene.util.AttributeFactory factory, int precisionStep) Deprecated.Expert: Creates a token stream for numeric values with the specifiedprecisionStepusing the givenAttributeFactory. The stream is not yet initialized, before using set a value using the various set???Value() methods.
-
-
Method Details
-
setLongValue
Deprecated.Initializes the token stream with the suppliedlongvalue.- Parameters:
value- the value, for which this TokenStream should enumerate tokens.- Returns:
- this instance, because of this you can use it the following way:
new Field(name, new LegacyNumericTokenStream(precisionStep).setLongValue(value))
-
setIntValue
Deprecated.Initializes the token stream with the suppliedintvalue.- Parameters:
value- the value, for which this TokenStream should enumerate tokens.- Returns:
- this instance, because of this you can use it the following way:
new Field(name, new LegacyNumericTokenStream(precisionStep).setIntValue(value))
-
setDoubleValue
Deprecated.Initializes the token stream with the supplieddoublevalue.- Parameters:
value- the value, for which this TokenStream should enumerate tokens.- Returns:
- this instance, because of this you can use it the following way:
new Field(name, new LegacyNumericTokenStream(precisionStep).setDoubleValue(value))
-
setFloatValue
Deprecated.Initializes the token stream with the suppliedfloatvalue.- Parameters:
value- the value, for which this TokenStream should enumerate tokens.- Returns:
- this instance, because of this you can use it the following way:
new Field(name, new LegacyNumericTokenStream(precisionStep).setFloatValue(value))
-
reset
public void reset()Deprecated.- Overrides:
resetin classorg.apache.lucene.analysis.TokenStream
-
incrementToken
public boolean incrementToken()Deprecated.- Specified by:
incrementTokenin classorg.apache.lucene.analysis.TokenStream
-
getPrecisionStep
public int getPrecisionStep()Deprecated.Returns the precision step. -
toString
Deprecated.- Overrides:
toStringin classorg.apache.lucene.util.AttributeSource
-
PointValuesinstead