Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class NumericTokenStream

    Expert: this class provides a TokenStream for indexing numeric values that can be used by NumericRangeQuery or NumericRangeFilter.

    Note that for simple usage, Int32Field, Int64Field, SingleField or DoubleField 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:
    IndexableFieldType fieldType = new IndexableFieldType(TextField.TYPE_NOT_STORED)
     {
         OmitNorms = true,
         IndexOptions = IndexOptions.DOCS_ONLY
     };
     Field field = new Field(name, new NumericTokenStream(precisionStep).SetInt32Value(value), fieldType);
     document.Add(field);

    For optimal performance, re-use the TokenStream and Field instance

    for more than one document:

    NumericTokenStream stream = new NumericTokenStream(precisionStep);
     IndexableFieldType fieldType = new IndexableFieldType(TextField.TYPE_NOT_STORED)
     {
         OmitNorms = true,
         IndexOptions = IndexOptions.DOCS_ONLY
     };
     Field field = new Field(name, stream, fieldType);
     Document document = new Document();
     document.Add(field);
    
     for(all documents) 
     {
         stream.SetInt32Value(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.

    @since 2.9

    Inheritance
    object
    AttributeSource
    TokenStream
    NumericTokenStream
    Implements
    IDisposable
    Inherited Members
    TokenStream.End()
    TokenStream.Dispose()
    AttributeSource.GetAttributeFactory()
    AttributeSource.GetAttributeClassesEnumerator()
    AttributeSource.GetAttributeImplsEnumerator()
    AttributeSource.AddAttributeImpl(Attribute)
    AttributeSource.AddAttribute<T>()
    AttributeSource.HasAttributes
    AttributeSource.HasAttribute<T>()
    AttributeSource.GetAttribute<T>()
    AttributeSource.ClearAttributes()
    AttributeSource.CaptureState()
    AttributeSource.RestoreState(AttributeSource.State)
    AttributeSource.GetHashCode()
    AttributeSource.Equals(object)
    AttributeSource.ReflectAsString(bool)
    AttributeSource.ReflectWith(IAttributeReflector)
    AttributeSource.CloneAttributes()
    AttributeSource.CopyTo(AttributeSource)
    AttributeSource.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Analysis
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class NumericTokenStream : TokenStream, IDisposable

    Constructors

    NumericTokenStream()

    Creates a token stream for numeric values using the default precisionStepPRECISION_STEP_DEFAULT (4). The stream is not yet initialized, before using set a value using the various Set???Value() methods.

    Declaration
    public NumericTokenStream()

    NumericTokenStream(AttributeFactory, int)

    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.

    Declaration
    public NumericTokenStream(AttributeSource.AttributeFactory factory, int precisionStep)
    Parameters
    Type Name Description
    AttributeSource.AttributeFactory factory
    int precisionStep

    NumericTokenStream(int)

    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.

    Declaration
    public NumericTokenStream(int precisionStep)
    Parameters
    Type Name Description
    int precisionStep

    Fields

    TOKEN_TYPE_FULL_PREC

    The full precision token gets this token type assigned.

    Declaration
    public const string TOKEN_TYPE_FULL_PREC = "fullPrecNumeric"
    Field Value
    Type Description
    string

    TOKEN_TYPE_LOWER_PREC

    The lower precision tokens gets this token type assigned.

    Declaration
    public const string TOKEN_TYPE_LOWER_PREC = "lowerPrecNumeric"
    Field Value
    Type Description
    string

    Properties

    PrecisionStep

    Returns the precision step.

    Declaration
    public int PrecisionStep { get; }
    Property Value
    Type Description
    int

    Methods

    IncrementToken()

    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 IAttributes 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<T>() and GetAttribute<T>(), references to all IAttributes 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().
    Declaration
    public override bool IncrementToken()
    Returns
    Type Description
    bool

    false for end of stream; true otherwise

    Overrides
    TokenStream.IncrementToken()

    Reset()

    This method is called by a consumer before it begins consumption using IncrementToken().

    Resets this stream to a clean state. Stateful implementations must implement this method so that they can be reused, just as if they had been created fresh.

    If you override this method, always call base.Reset(), otherwise some internal state will not be correctly reset (e.g., Tokenizer will throw InvalidOperationException on further usage).
    Declaration
    public override void Reset()
    Overrides
    TokenStream.Reset()

    SetDoubleValue(double)

    Initializes the token stream with the supplied double value.

    Declaration
    public NumericTokenStream SetDoubleValue(double value)
    Parameters
    Type Name Description
    double value

    the value, for which this TokenStream should enumerate tokens.

    Returns
    Type Description
    NumericTokenStream

    this instance, because of this you can use it the following way:

    new Field(name, new NumericTokenStream(precisionStep).SetDoubleValue(value))

    SetInt32Value(int)

    Initializes the token stream with the supplied int value.

    NOTE: This was setIntValue() in Lucene
    Declaration
    public NumericTokenStream SetInt32Value(int value)
    Parameters
    Type Name Description
    int value

    the value, for which this TokenStream should enumerate tokens.

    Returns
    Type Description
    NumericTokenStream

    this instance, because of this you can use it the following way:

    new Field(name, new NumericTokenStream(precisionStep).SetInt32Value(value))

    SetInt64Value(long)

    Initializes the token stream with the supplied long value.

    NOTE: This was setLongValue() in Lucene
    Declaration
    public NumericTokenStream SetInt64Value(long value)
    Parameters
    Type Name Description
    long value

    the value, for which this TokenStream should enumerate tokens.

    Returns
    Type Description
    NumericTokenStream

    this instance, because of this you can use it the following way:

    new Field(name, new NumericTokenStream(precisionStep).SetInt64Value(value))

    SetSingleValue(float)

    Initializes the token stream with the supplied float value.

    NOTE: This was setFloatValue() in Lucene
    Declaration
    public NumericTokenStream SetSingleValue(float value)
    Parameters
    Type Name Description
    float value

    the value, for which this TokenStream should enumerate tokens.

    Returns
    Type Description
    NumericTokenStream

    this instance, because of this you can use it the following way:

    new Field(name, new NumericTokenStream(precisionStep).SetSingleValue(value))

    Implements

    IDisposable
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.