Class SynonymFilter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Unwrappable<TokenStream>
Note that with the current implementation, parsing is greedy, so whenever multiple parses would apply, the rule starting the earliest and parsing the most tokens wins. For example if you have these rules:
a -> x a b -> y b c d -> zThen input
a b c d e
parses to y b c
d
, ie the 2nd rule "wins" because it started earliest and matched the most input tokens of
other rules starting at that point.
A future improvement to this filter could allow non-greedy parsing, such that the 3rd rule would win, and also separately allow multiple parses, such that all 3 rules would match, perhaps even on a rule by rule basis.
NOTE: when a match occurs, the output tokens associated with the matching rule are
"stacked" on top of the input stream (if the rule had keepOrig=true
) and also on top
of another matched rule's output tokens. This is not a correct solution, as really the output
should be an arbitrary graph/lattice. For example, with the above match, you would expect an
exact PhraseQuery
"y b
c"
to match the parsed tokens, but it will fail to do so. This limitation is necessary
because Lucene's TokenStream (and index) cannot yet represent an arbitrary graph.
NOTE: If multiple incoming tokens arrive on the same position, only the first token at that position is used for parsing. Subsequent tokens simply pass through and are not parsed. A future improvement would be to allow these tokens to also be matched.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Deprecated.private static class
Deprecated.Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
AttributeSource.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteArrayDataInput
Deprecated.private int
Deprecated.private boolean
Deprecated.Deprecated.private final FST.BytesReader
Deprecated.private final SynonymFilter.PendingInput[]
Deprecated.private final SynonymFilter.PendingOutputs[]
Deprecated.private final boolean
Deprecated.private int
Deprecated.private int
Deprecated.private int
Deprecated.private int
Deprecated.private int
Deprecated.private final OffsetAttribute
Deprecated.private final PositionIncrementAttribute
Deprecated.private final PositionLengthAttribute
Deprecated.private final int
Deprecated.Deprecated.private final BytesRef
Deprecated.private final CharsRefBuilder
Deprecated.private final SynonymMap
Deprecated.private final CharTermAttribute
Deprecated.static final String
Deprecated.private final TypeAttribute
Deprecated.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
ConstructorsConstructorDescriptionSynonymFilter
(TokenStream input, SynonymMap synonyms, boolean ignoreCase) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Deprecated.private void
capture()
Deprecated.(package private) int
Deprecated.boolean
Deprecated.Consumers (i.e.,IndexWriter
) use this method to advance the stream to the next token.private void
parse()
Deprecated.void
reset()
Deprecated.This method is called by a consumer before it begins consumption usingTokenStream.incrementToken()
.private int
rollIncr
(int count) Deprecated.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
Deprecated.- See Also:
-
synonyms
Deprecated. -
ignoreCase
private final boolean ignoreCaseDeprecated. -
rollBufferSize
private final int rollBufferSizeDeprecated. -
captureCount
private int captureCountDeprecated. -
termAtt
Deprecated. -
posIncrAtt
Deprecated. -
posLenAtt
Deprecated. -
typeAtt
Deprecated. -
offsetAtt
Deprecated. -
inputSkipCount
private int inputSkipCountDeprecated. -
futureInputs
Deprecated. -
bytesReader
Deprecated. -
futureOutputs
Deprecated. -
nextWrite
private int nextWriteDeprecated. -
nextRead
private int nextReadDeprecated. -
finished
private boolean finishedDeprecated. -
scratchArc
Deprecated. -
fst
Deprecated. -
fstReader
Deprecated. -
scratchBytes
Deprecated. -
scratchChars
Deprecated. -
lastStartOffset
private int lastStartOffsetDeprecated. -
lastEndOffset
private int lastEndOffsetDeprecated.
-
-
Constructor Details
-
SynonymFilter
Deprecated.- 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
-
capture
private void capture()Deprecated. -
parse
Deprecated.- Throws:
IOException
-
addOutput
Deprecated. -
rollIncr
private int rollIncr(int count) Deprecated. -
getCaptureCount
int getCaptureCount()Deprecated. -
incrementToken
Deprecated.Description copied from class:TokenStream
Consumers (i.e.,IndexWriter
) use this method to advance the stream to the next token. Implementing classes must implement this method and update the appropriateAttributeImpl
s with the attributes of the next token.The producer must make no assumptions about the attributes after the method has been returned: the caller may arbitrarily change it. If the producer needs to preserve the state for subsequent calls, it can use
AttributeSource.captureState()
to create a copy of the current attribute state.This method is called for every token of a document, so an efficient implementation is crucial for good performance. To avoid calls to
AttributeSource.addAttribute(Class)
andAttributeSource.getAttribute(Class)
, references to allAttributeImpl
s that this stream uses should be retrieved during instantiation.To ensure that filters and consumers know which attributes are available, the attributes must be added during instantiation. Filters and consumers are not required to check for availability of attributes in
TokenStream.incrementToken()
.- Specified by:
incrementToken
in classTokenStream
- Returns:
- false for end of stream; true otherwise
- Throws:
IOException
-
reset
Deprecated.Description copied from class:TokenFilter
This method is called by a consumer before it begins consumption usingTokenStream.incrementToken()
.Resets this stream to a clean state. Stateful implementations must implement this method so that they can be reused, just as if they had been created fresh.
If you override this method, always call
super.reset()
, otherwise some internal state will not be correctly reset (e.g.,Tokenizer
will throwIllegalStateException
on further usage).NOTE: The default implementation chains the call to the input TokenStream, so be sure to call
super.reset()
when overriding this method.- Overrides:
reset
in classTokenFilter
- Throws:
IOException
-
SynonymGraphFilter
instead, but be sure to also useFlattenGraphFilter
at index time (not at search time) as well.