org.apache.lucene.analysis.miscellaneous

## Class ConditionalTokenFilter

- java.lang.Object
- - org.apache.lucene.util.AttributeSource
  - - org.apache.lucene.analysis.TokenStream
    - - org.apache.lucene.analysis.TokenFilter
      - - org.apache.lucene.analysis.miscellaneous.ConditionalTokenFilter

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    ProtectedTermFilter

      public abstract class ConditionalTokenFilter
      extends TokenFilter

  Allows skipping TokenFilters based on the current set of attributes. To use, implement the `shouldFilter()` method. If it returns `true`, then calling `incrementToken()` will use the wrapped TokenFilter(s) to make changes to the tokenstream. If it returns `false`, then the wrapped filter(s) will be skipped.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource

      `AttributeSource.State`

  - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.analysis.TokenFilter

      `input`

    - ### Fields inherited from class org.apache.lucene.analysis.TokenStream

      `DEFAULT_TOKEN_ATTRIBUTE_FACTORY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ConditionalTokenFilter(TokenStream input, Function<TokenStream,TokenStream> inputFactory)` Create a new ConditionalTokenFilter

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `end()`
    `boolean` | `incrementToken()`
    `void` | `reset()`
    `protected abstract boolean` | `shouldFilter()` Whether or not to execute the wrapped TokenFilter(s) for the current token

    - ### Methods inherited from class org.apache.lucene.util.AttributeSource

      `addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ConditionalTokenFilter

          protected ConditionalTokenFilter(TokenStream input,
                                           Function<TokenStream,TokenStream> inputFactory)

      Create a new ConditionalTokenFilter
      Parameters:
        `input` - the input TokenStream
        `inputFactory` - a factory function to create the wrapped filter(s)

  - ### Method Detail

    - #### shouldFilter

          protected abstract boolean shouldFilter()
                                           throws IOException

      Whether or not to execute the wrapped TokenFilter(s) for the current token
      Throws:
        `IOException`

    - #### reset

          public void reset()
                     throws IOException

      Overrides:
        `reset` in class `TokenFilter`
      Throws:
        `IOException`

    - #### end

          public void end()
                   throws IOException

      Overrides:
        `end` in class `TokenFilter`
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `TokenFilter`
      Throws:
        `IOException`

    - #### incrementToken

          public final boolean incrementToken()
                                       throws IOException

      Specified by:
        `incrementToken` in class `TokenStream`
      Throws:
        `IOException`

Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.