org.apache.lucene.analysis.synonym

## Class SynonymGraphFilter

- java.lang.Object
- - org.apache.lucene.util.AttributeSource
  - - org.apache.lucene.analysis.TokenStream
    - - org.apache.lucene.analysis.TokenFilter
      - - org.apache.lucene.analysis.synonym.SynonymGraphFilter

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public final class SynonymGraphFilter
      extends TokenFilter

  Applies single- or multi-token synonyms from a `SynonymMap` to an incoming `TokenStream`, producing a fully correct graph output. This is a replacement for `SynonymFilter`, which produces incorrect graphs for multi-token synonyms.

  However, if you use this during indexing, you must follow it with `FlattenGraphFilter` to squash tokens on top of one another like `SynonymFilter`, because the indexer can't directly consume a graph. To get fully correct positional queries when your synonym replacements are multiple tokens, you should instead apply synonyms using this `TokenFilter` at query time and translate the resulting graph to a `TermAutomatonQuery` e.g. using `TokenStreamToTermAutomatonQuery`.

  NOTE: this cannot consume an incoming graph; results will be undefined.

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

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

      `AttributeSource.State`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `TYPE_SYNONYM`

    - ### 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
    Constructor and Description
    `SynonymGraphFilter(TokenStream input, SynonymMap synonyms, boolean ignoreCase)` Apply previously built synonyms to incoming tokens.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `incrementToken()`
    `void` | `reset()`

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

      `close, end`

    - ### 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`

- - ### Field Detail

    - #### TYPE_SYNONYM

          public static final String TYPE_SYNONYM

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SynonymGraphFilter

          public SynonymGraphFilter(TokenStream input,
                                    SynonymMap synonyms,
                                    boolean ignoreCase)

      Apply previously built synonyms to incoming tokens.
      Parameters:
        `input` - input tokenstream
        `synonyms` - synonym map
        `ignoreCase` - case-folds input for matching with `Character.toLowerCase(int)`. Note, if you set this to true, it's your responsibility to lowercase the input entries when you create the `SynonymMap`

  - ### Method Detail

    - #### incrementToken

          public boolean incrementToken()
                                 throws IOException

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

    - #### reset

          public void reset()
                     throws IOException

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

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