org.apache.lucene.analysis

Class LegacyNumericTokenStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    Deprecated. 
    Please switch to PointValues instead

    @Deprecated
    public final class LegacyNumericTokenStream
    extends TokenStream
    Expert: This class provides a 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
    • Constructor Detail

      • LegacyNumericTokenStream

        public LegacyNumericTokenStream(int precisionStep)
        Deprecated. 
        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.
      • LegacyNumericTokenStream

        public LegacyNumericTokenStream(AttributeFactory factory,
                                        int precisionStep)
        Deprecated. 
        Expert: Creates a token stream for numeric values with the specified precisionStep using the given AttributeFactory. The stream is not yet initialized, before using set a value using the various set???Value() methods.
    • Method Detail

      • setLongValue

        public LegacyNumericTokenStream setLongValue(long value)
        Deprecated. 
        Initializes the token stream with the supplied long value.
        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

        public LegacyNumericTokenStream setIntValue(int value)
        Deprecated. 
        Initializes the token stream with the supplied int value.
        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

        public LegacyNumericTokenStream setDoubleValue(double value)
        Deprecated. 
        Initializes the token stream with the supplied double value.
        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

        public LegacyNumericTokenStream setFloatValue(float value)
        Deprecated. 
        Initializes the token stream with the supplied float value.
        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. 
        Description copied from class: TokenStream
        This method is called by a consumer before it begins consumption using TokenStream.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 super.reset(), otherwise some internal state will not be correctly reset (e.g., Tokenizer will throw IllegalStateException on further usage).

        Overrides:
        reset in class TokenStream
      • incrementToken

        public boolean incrementToken()
        Deprecated. 
        Description copied from class: TokenStream
        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 AttributeImpls 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 AttributeSource.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 AttributeSource.addAttribute(Class) and AttributeSource.getAttribute(Class), references to all AttributeImpls 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 TokenStream.incrementToken().

        Specified by:
        incrementToken in class TokenStream
        Returns:
        false for end of stream; true otherwise
      • getPrecisionStep

        public int getPrecisionStep()
        Deprecated. 
        Returns the precision step.