java.lang.Object | |||
↳ | org.apache.lucene.util.AttributeSource | ||
↳ | org.apache.lucene.analysis.TokenStream | ||
↳ | org.apache.lucene.analysis.NumericTokenStream |
Expert: This class provides a TokenStream
for indexing numeric values that can be used by NumericRangeQuery
or NumericRangeFilter
.
Note that for simple usage, NumericField
is
recommended. NumericField
disables norms and
term freqs, as they are not usually needed during
searching. If you need to change these settings, you
should use this class.
See NumericField
for capabilities of fields
indexed numerically.
Here's an example usage, for an int
field:
Field field = new Field(name, new NumericTokenStream(precisionStep).setIntValue(value)); field.setOmitNorms(true); field.setOmitTermFreqAndPositions(true); document.add(field);
For optimal performance, re-use the TokenStream and Field instance for more than one document:
NumericTokenStream stream = new NumericTokenStream(precisionStep); Field field = new Field(name, stream); field.setOmitNorms(true); field.setOmitTermFreqAndPositions(true); 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 NumericTokenStream
instance for each.
See NumericRangeQuery
for more details on the
precisionStep
parameter as well as how numeric fields work under the hood.
NOTE: This API is experimental and might change in incompatible ways in the next release.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | TOKEN_TYPE_FULL_PREC | The full precision token gets this token type assigned. | |||||||||
String | TOKEN_TYPE_LOWER_PREC | The lower precision tokens gets this token type assigned. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a token stream for numeric values using the default
precisionStep
PRECISION_STEP_DEFAULT (4). | |||||||||||
Creates a token stream for numeric values with the specified
precisionStep . | |||||||||||
Expert: Creates a token stream for numeric values with the specified
precisionStep using the given AttributeSource . | |||||||||||
Expert: Creates a token stream for numeric values with the specified
precisionStep using the given
AttributeSource.AttributeFactory . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Consumers (i.e.,
IndexWriter ) use this method to advance the stream to
the next token. | |||||||||||
Resets this stream to the beginning.
| |||||||||||
Initializes the token stream with the supplied
double value. | |||||||||||
Initializes the token stream with the supplied
float value. | |||||||||||
Initializes the token stream with the supplied
int value. | |||||||||||
Initializes the token stream with the supplied
long value. | |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.lucene.analysis.TokenStream
| |||||||||||
From class
org.apache.lucene.util.AttributeSource
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.io.Closeable
|
The full precision token gets this token type assigned.
The lower precision tokens gets this token type assigned.
Creates a token stream for numeric values using the default precisionStep
PRECISION_STEP_DEFAULT
(4). The stream is not yet initialized,
before using set a value using the various set???Value() methods.
Creates a token stream for numeric values with the specified
precisionStep
. The stream is not yet initialized,
before using set a value using the various set???Value() methods.
Expert: Creates a token stream for numeric values with the specified
precisionStep
using the given AttributeSource
.
The stream is not yet initialized,
before using set a value using the various set???Value() methods.
Expert: Creates a token stream for numeric values with the specified
precisionStep
using the given
AttributeSource.AttributeFactory
.
The stream is not yet initialized,
before using set a value using the various set???Value() methods.
Consumers (i.e., IndexWriter
) use this method to advance the stream to
the next token. Implementing classes must implement this method and update
the appropriate AttributeImpl
s with the attributes of the next
token.
The producer must make no assumptions about the attributes after the method
has been returned: the caller may arbitrarily change it. If the producer
needs to preserve the state for subsequent calls, it can use
captureState()
to create a copy of the current attribute state.
This method is called for every token of a document, so an efficient
implementation is crucial for good performance. To avoid calls to
addAttribute(Class)
and getAttribute(Class)
,
references to all AttributeImpl
s that this stream uses should be
retrieved during instantiation.
To ensure that filters and consumers know which attributes are available,
the attributes must be added during instantiation. Filters and consumers
are not required to check for availability of attributes in
incrementToken()
.
Resets this stream to the beginning. This is an optional operation, so
subclasses may or may not implement this method. reset()
is not needed for
the standard indexing process. However, if the tokens of a
TokenStream
are intended to be consumed more than once, it is
necessary to implement reset()
. Note that if your TokenStream
caches tokens and feeds them back again after a reset, it is imperative
that you clone the tokens when you store them away (on the first pass) as
well as when you return them (on future passes after reset()
).
Initializes the token stream with the supplied double
value.
value | the value, for which this TokenStream should enumerate tokens. |
---|
new Field(name, new NumericTokenStream(precisionStep).setDoubleValue(value))
Initializes the token stream with the supplied float
value.
value | the value, for which this TokenStream should enumerate tokens. |
---|
new Field(name, new NumericTokenStream(precisionStep).setFloatValue(value))
Initializes the token stream with the supplied int
value.
value | the value, for which this TokenStream should enumerate tokens. |
---|
new Field(name, new NumericTokenStream(precisionStep).setIntValue(value))
Initializes the token stream with the supplied long
value.
value | the value, for which this TokenStream should enumerate tokens. |
---|
new Field(name, new NumericTokenStream(precisionStep).setLongValue(value))