Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Public Member Functions | Properties | List of all members
Lucene.Net.Documents.NumericField Class Reference

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: More...

Inherits Lucene.Net.Documents.AbstractField.

Public Member Functions

 NumericField (System.String name)
 Creates a field for numeric values using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods. This constructor creates an indexed, but not stored field.
 
 NumericField (System.String name, Field.Store store, bool index)
 Creates a field for numeric values using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods.
 
 NumericField (System.String name, int precisionStep)
 Creates a field for numeric values with the specified precisionStep. The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods. This constructor creates an indexed, but not stored field.
 
 NumericField (System.String name, int precisionStep, Field.Store store, bool index)
 Creates a field for numeric values with the specified precisionStep. The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods.
 
override byte[] GetBinaryValue (byte[] result)
 Returns always null for numeric fields
 
NumericField SetLongValue (long value_Renamed)
 Initializes the field with the supplied long value.
 
NumericField SetIntValue (int value_Renamed)
 Initializes the field with the supplied int value.
 
NumericField SetDoubleValue (double value_Renamed)
 Initializes the field with the supplied double value.
 
NumericField SetFloatValue (float value_Renamed)
 Initializes the field with the supplied float value.
 
- Public Member Functions inherited from Lucene.Net.Documents.AbstractField
virtual byte[] GetBinaryValue ()
 Return the raw byte[] for the binary field. Note that you must also call BinaryLength and BinaryOffset to know which range of bytes in this returned array belong to the field.
 
override System.String ToString ()
 Prints a Field for human consumption.
 

Properties

override TokenStream TokenStreamValue [get]
 Returns a NumericTokenStream for indexing the numeric value.
 
override TextReader ReaderValue [get]
 Returns always null for numeric fields
 
override string StringValue [get]
 Returns the numeric value as a string (how it is stored, when Field.Store.YES is chosen).
 
ValueType NumericValue [get]
 Returns the current numeric value as a subclass of Number, null if not yet initialized.
 
- Properties inherited from Lucene.Net.Documents.AbstractField
virtual float Boost [get, set]
 Gets or sets the boost factor for hits for this field.
 
virtual string Name [get]
 Returns the name of the field as an interned string. For example "date", "title", "body", ...
 
bool IsStored [get]
 True iff the value of the field is to be stored in the index for return with search hits. It is an error for this to be true if a field is Reader-valued.
 
bool IsIndexed [get]
 True iff the value of the field is to be indexed, so that it may be searched on.
 
bool IsTokenized [get]
 True iff the value of the field should be tokenized as text prior to indexing. Un-tokenized fields are indexed as a single word and may not be Reader-valued.
 
bool IsTermVectorStored [get]
 True iff the term or terms used to index this field are stored as a term vector, available from Lucene.Net.Index.IndexReader.GetTermFreqVector(int,String). These methods do not provide access to the original content of the field, only to terms used to index it. If the original content must be preserved, use the stored attribute instead.
 
virtual bool IsStoreOffsetWithTermVector [get]
 True iff terms are stored as term vector together with their offsets (start and end position in source text).
 
virtual bool IsStorePositionWithTermVector [get]
 True iff terms are stored as term vector together with their token positions.
 
bool IsBinary [get]
 True iff the value of the filed is stored as binary
 
virtual int BinaryLength [get]
 Returns length of byte[] segment that is used as value, if Field is not binary returned value is undefined
 
virtual int BinaryOffset [get]
 Returns offset into byte[] segment that is used as value, if Field is not binary returned value is undefined
 
virtual bool OmitNorms [get, set]
 True if norms are omitted for this indexed field
 
virtual bool OmitTermFreqAndPositions [get, set]
 Expert:
 
virtual bool IsLazy [get]
 
abstract TokenStream TokenStreamValue [get]
 
abstract TextReader ReaderValue [get]
 
abstract string StringValue [get]
 
- Properties inherited from Lucene.Net.Documents.IFieldable
float Boost [get, set]
 Gets or sets the boost factor for hits for this field. This value will be multiplied into the score of all hits on this this field of this document.
 
string Name [get]
 Returns the name of the field as an interned string. For example "date", "title", "body", ...
 
string StringValue [get]
 The value of the field as a String, or null. For indexing, if isStored()==true, the stringValue() will be used as the stored field value unless isBinary()==true, in which case GetBinaryValue() will be used.
 
TextReader ReaderValue [get]
 The value of the field as a Reader, which can be used at index time to generate indexed tokens.
 
TokenStream TokenStreamValue [get]
 The TokenStream for this field to be used when indexing, or null.
 
bool IsStored [get]
 True if the value of the field is to be stored in the index for return with search hits.
 
bool IsIndexed [get]
 True if the value of the field is to be indexed, so that it may be searched on.
 
bool IsTokenized [get]
 True if the value of the field should be tokenized as text prior to indexing. Un-tokenized fields are indexed as a single word and may not be Reader-valued.
 
bool IsTermVectorStored [get]
 True if the term or terms used to index this field are stored as a term vector, available from Lucene.Net.Index.IndexReader.GetTermFreqVector(int,String). These methods do not provide access to the original content of the field, only to terms used to index it. If the original content must be preserved, use the stored attribute instead.
 
bool IsStoreOffsetWithTermVector [get]
 True if terms are stored as term vector together with their offsets (start and end positon in source text).
 
bool IsStorePositionWithTermVector [get]
 True if terms are stored as term vector together with their token positions.
 
bool IsBinary [get]
 True if the value of the field is stored as binary
 
bool OmitNorms [get, set]
 True if norms are omitted for this indexed field.
 
bool IsLazy [get]
 Indicates whether a Field is Lazy or not. The semantics of Lazy loading are such that if a Field is lazily loaded, retrieving it's values via StringValue() or GetBinaryValue() is only valid as long as the Lucene.Net.Index.IndexReader that retrieved the Document is still open.
 
int BinaryOffset [get]
 Returns offset into byte[] segment that is used as value, if Field is not binary returned value is undefined
 
int BinaryLength [get]
 Returns length of byte[] segment that is used as value, if Field is not binary returned value is undefined
 
bool OmitTermFreqAndPositions [get, set]
 

Detailed Description

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 System.DateTime can be translated into a long value using the 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 SortField.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 NumericField(String,Field.Store,bool) constructor if you need to change these defaults.

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 NumericField(String,int,Field.Store,bool) if you'd like to change the value. Note that you must also specify a congruent value when creating NumericRangeQuery{T} or NumericRangeFilter{T}. For low cardinality fields larger precision steps are good. If the cardinality is < 100, it is fair to use int.MaxValue, which produces one term per value.

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 NumericUtils.

If you only need to sort by numeric value, and never run range querying/filtering, you can index using a precisionStep of int.MaxValue. This will minimize disk space consumed.

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 Strings (according to toString(value) of the used data type).

<font color="red">NOTE: This API is experimental and might change in incompatible ways in the next release.</font>

<since> 2.9 </since>

Definition at line 145 of file NumericField.cs.

Constructor & Destructor Documentation

Lucene.Net.Documents.NumericField.NumericField ( System.String  name)

Creates a field for numeric values using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods. This constructor creates an indexed, but not stored field.

Parameters
namethe field name

Definition at line 158 of file NumericField.cs.

Lucene.Net.Documents.NumericField.NumericField ( System.String  name,
Field.Store  store,
bool  index 
)

Creates a field for numeric values using the default precisionStep NumericUtils.PRECISION_STEP_DEFAULT (4). The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods.

Parameters
namethe field name
storeif the field should be stored in plain text form (according to toString(value) of the used data type)
indexif the field should be indexed using NumericTokenStream

Definition at line 174 of file NumericField.cs.

Lucene.Net.Documents.NumericField.NumericField ( System.String  name,
int  precisionStep 
)

Creates a field for numeric values with the specified precisionStep. The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods. This constructor creates an indexed, but not stored field.

Parameters
namethe field name
precisionStepthe used precision step

Definition at line 188 of file NumericField.cs.

Lucene.Net.Documents.NumericField.NumericField ( System.String  name,
int  precisionStep,
Field.Store  store,
bool  index 
)

Creates a field for numeric values with the specified precisionStep. The instance is not yet initialized with a numeric value, before indexing a document containing this field, set a value using the various set???Value() methods.

Parameters
namethe field name
precisionStepthe used precision step
storeif the field should be stored in plain text form (according to toString(value) of the used data type)
indexif the field should be indexed using NumericTokenStream

Definition at line 206 of file NumericField.cs.

Member Function Documentation

override byte [] Lucene.Net.Documents.NumericField.GetBinaryValue ( byte[]  result)
virtual

Returns always null for numeric fields

Reimplemented from Lucene.Net.Documents.AbstractField.

Definition at line 219 of file NumericField.cs.

NumericField Lucene.Net.Documents.NumericField.SetDoubleValue ( double  value_Renamed)

Initializes the field with the supplied double value.

Parameters
value_Renamedthe numeric value
Returns
this instance, because of this you can use it the following way: document.add(new NumericField(name, precisionStep).setDoubleValue(value))

Definition at line 274 of file NumericField.cs.

NumericField Lucene.Net.Documents.NumericField.SetFloatValue ( float  value_Renamed)

Initializes the field with the supplied float value.

Parameters
value_Renamedthe numeric value
Returns
this instance, because of this you can use it the following way: document.add(new NumericField(name, precisionStep).setFloatValue(value))

Definition at line 287 of file NumericField.cs.

NumericField Lucene.Net.Documents.NumericField.SetIntValue ( int  value_Renamed)

Initializes the field with the supplied int value.

Parameters
value_Renamedthe numeric value
Returns
this instance, because of this you can use it the following way: document.add(new NumericField(name, precisionStep).setIntValue(value))

Definition at line 261 of file NumericField.cs.

NumericField Lucene.Net.Documents.NumericField.SetLongValue ( long  value_Renamed)

Initializes the field with the supplied long value.

Parameters
value_Renamedthe numeric value
Returns
this instance, because of this you can use it the following way: document.add(new NumericField(name, precisionStep).SetLongValue(value))

Definition at line 248 of file NumericField.cs.

Property Documentation

ValueType Lucene.Net.Documents.NumericField.NumericValue
get

Returns the current numeric value as a subclass of Number, null if not yet initialized.

Definition at line 238 of file NumericField.cs.

override TextReader Lucene.Net.Documents.NumericField.ReaderValue
get

Returns always null for numeric fields

Definition at line 226 of file NumericField.cs.

override string Lucene.Net.Documents.NumericField.StringValue
get

Returns the numeric value as a string (how it is stored, when Field.Store.YES is chosen).

Definition at line 232 of file NumericField.cs.

override TokenStream Lucene.Net.Documents.NumericField.TokenStreamValue
get

Returns a NumericTokenStream for indexing the numeric value.

Definition at line 214 of file NumericField.cs.


The documentation for this class was generated from the following file: