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,Unwrappable<TokenStream>
public final class SynonymGraphFilter extends TokenFilter
Applies single- or multi-token synonyms from aSynonymMapto an incomingTokenStream, producing a fully correct graph output. This is a replacement forSynonymFilter, which produces incorrect graphs for multi-token synonyms.However, if you use this during indexing, you must follow it with
FlattenGraphFilterto squash tokens on top of one another likeSynonymFilter, 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 thisTokenFilterat query time and translate the resulting graph to aTermAutomatonQuerye.g. usingTokenStreamToTermAutomatonQuery.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 Description static StringTYPE_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 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 Description booleanincrementToken()voidreset()-
Methods inherited from class org.apache.lucene.analysis.TokenFilter
close, end, unwrap
-
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
-
-
-
-
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 tokenstreamsynonyms- synonym mapignoreCase- case-folds input for matching withCharacter.toLowerCase(int). Note, if you set this to true, it's your responsibility to lowercase the input entries when you create theSynonymMap
-
-
Method Detail
-
incrementToken
public boolean incrementToken() throws IOException- Specified by:
incrementTokenin classTokenStream- Throws:
IOException
-
reset
public void reset() throws IOException- Overrides:
resetin classTokenFilter- Throws:
IOException
-
-