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>
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
FieldsFields inherited from class org.apache.lucene.analysis.TokenFilter
input
Fields inherited from class org.apache.lucene.analysis.TokenStream
DEFAULT_TOKEN_ATTRIBUTE_FACTORY
-
Constructor Summary
ConstructorsConstructorDescriptionSynonymGraphFilter
(TokenStream input, SynonymMap synonyms, boolean ignoreCase) Apply previously built synonyms to incoming tokens. -
Method Summary
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 Details
-
TYPE_SYNONYM
- See Also:
-
-
Constructor Details
-
SynonymGraphFilter
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 Details
-
incrementToken
- Specified by:
incrementToken
in classTokenStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classTokenFilter
- Throws:
IOException
-