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