Class NumericField
This class provides a Field that enables indexing of numeric values for efficient range filtering and sorting. Here's an example usage, adding an int value:
document.add(new NumericField(name).setIntValue(value));
For optimal performance, re-use the
NumericField
and Document instance for more than
one document:
NumericField field = new NumericField(name);
Document document = new Document();
document.add(field);
for(all documents) {
...
field.setIntValue(value)
writer.addDocument(document);
...
}
The .Net native types int
, long
,
float
and double
are
directly supported. However, any value that can be
converted into these native types can also be indexed.
For example, date/time values represented by a
java.util.Date.getTime
method. If you
don't need millisecond precision, you can quantize the
value, either by dividing the result of
java.util.Date.getTime
or using the separate getters
(for year, month, etc.) to construct an int
or
long
value.
To perform range querying or filtering against a
NumericField
, use NumericRangeQuery<T> or NumericRangeFilter<T>
. To sort according to a
NumericField
, use the normal numeric sort types, eg
INT NumericField
values
can also be loaded directly from FieldCache.
By default, a NumericField
's value is not stored but
is indexed for range filtering and sorting. You can use
the
You may add the same field name as a NumericField
to
the same document more than once. Range querying and
filtering will be the logical OR of all values; so a range query
will hit all documents that have at least one value in
the range. However sort behavior is not defined. If you need to sort,
you should separately index a single-valued NumericField
.
A NumericField
will consume somewhat more disk space
in the index than an ordinary single-valued field.
However, for a typical index that includes substantial
textual content per document, this increase will likely
be in the noise.
Within Lucene, each numeric value is indexed as a
trie structure, where each term is logically
assigned to larger and larger pre-defined brackets (which
are simply lower-precision representations of the value).
The step size between each successive bracket is called the
precisionStep
, measured in bits. Smaller
precisionStep
values result in larger number
of brackets, which consumes more disk space in the index
but may result in faster range search performance. The
default value, 4, was selected for a reasonable tradeoff
of disk space consumption versus performance. You can
use the expert constructor
For more information on the internals of numeric trie
indexing, including the precisionStep
configuration, see NumericRangeQuery<T>. The format of
indexed values is described in Lucene.Net.Util.NumericUtils.
If you only need to sort by numeric value, and never
run range querying/filtering, you can index using a
precisionStep
of
More advanced users can instead use NumericTokenStream directly, when indexing numbers. This class is a wrapper around this token stream type for easier, more intuitive usage.
NOTE: This class is only used during
indexing. When retrieving the stored field value from a
Document instance after search, you will get a
conventional IFieldable instance where the numeric
values are returned as toString(value)
of the used data type).
NOTE: This API is experimental and might change in incompatible ways in the next release.
Inherited Members
Namespace:
Assembly: Lucene.Net.NetCore.dll
Syntax
public sealed class NumericField : AbstractField, IFieldable
Constructors
Name | Description |
---|---|
NumericField(String) | Creates a field for numeric values using the default |
NumericField(String, Field.Store, Boolean) | Creates a field for numeric values using the default |
NumericField(String, Int32) | Creates a field for numeric values with the specified
|
NumericField(String, Int32, Field.Store, Boolean) | Creates a field for numeric values with the specified
|
Properties
Name | Description |
---|---|
NumericValue | Returns the current numeric value as a subclass of |
ReaderValue | Returns always |
StringValue | Returns the numeric value as a string (how it is stored, when YES is chosen). |
TokenStreamValue | Returns a NumericTokenStream for indexing the numeric value. |
Methods
Name | Description |
---|---|
GetBinaryValue(Byte[]) | Returns always |
SetDoubleValue(Double) | Initializes the field with the supplied |
SetFloatValue(Single) | Initializes the field with the supplied |
SetIntValue(Int32) | Initializes the field with the supplied |
SetLongValue(Int64) | Initializes the field with the supplied |