public class PrefixAwareTokenFilter extends TokenStream
NOTE: This filter might not behave correctly if used with custom Attributes, i.e. Attributes other than the ones located in org.apache.lucene.analysis.tokenattributes.
AttributeSource.State
Modifier and Type | Field and Description |
---|---|
private FlagsAttribute |
flagsAtt |
private OffsetAttribute |
offsetAtt |
private FlagsAttribute |
p_flagsAtt |
private OffsetAttribute |
p_offsetAtt |
private PayloadAttribute |
p_payloadAtt |
private PositionIncrementAttribute |
p_posIncrAtt |
private CharTermAttribute |
p_termAtt |
private TypeAttribute |
p_typeAtt |
private PayloadAttribute |
payloadAtt |
private PositionIncrementAttribute |
posIncrAtt |
private TokenStream |
prefix |
private boolean |
prefixExhausted |
private Token |
previousPrefixToken |
private Token |
reusableToken |
private TokenStream |
suffix |
private CharTermAttribute |
termAtt |
private TypeAttribute |
typeAtt |
DEFAULT_TOKEN_ATTRIBUTE_FACTORY
Constructor and Description |
---|
PrefixAwareTokenFilter(TokenStream prefix,
TokenStream suffix) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Releases resources associated with this stream.
|
void |
end()
This method is called by the consumer after the last token has been
consumed, after
TokenStream.incrementToken() returned false
(using the new TokenStream API). |
private Token |
getNextPrefixInputToken(Token token) |
private Token |
getNextSuffixInputToken(Token token) |
TokenStream |
getPrefix() |
TokenStream |
getSuffix() |
boolean |
incrementToken()
Consumers (i.e.,
IndexWriter ) use this method to advance the stream to
the next token. |
void |
reset()
This method is called by a consumer before it begins consumption using
TokenStream.incrementToken() . |
private void |
setCurrentToken(Token token) |
void |
setPrefix(TokenStream prefix) |
void |
setSuffix(TokenStream suffix) |
Token |
updateSuffixToken(Token suffixToken,
Token lastPrefixToken)
The default implementation adds last prefix token end offset to the suffix token start and end offsets.
|
addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString
private TokenStream prefix
private TokenStream suffix
private CharTermAttribute termAtt
private PositionIncrementAttribute posIncrAtt
private PayloadAttribute payloadAtt
private OffsetAttribute offsetAtt
private TypeAttribute typeAtt
private FlagsAttribute flagsAtt
private CharTermAttribute p_termAtt
private PositionIncrementAttribute p_posIncrAtt
private PayloadAttribute p_payloadAtt
private OffsetAttribute p_offsetAtt
private TypeAttribute p_typeAtt
private FlagsAttribute p_flagsAtt
private Token previousPrefixToken
private Token reusableToken
private boolean prefixExhausted
public PrefixAwareTokenFilter(TokenStream prefix, TokenStream suffix)
public final boolean incrementToken() throws java.io.IOException
TokenStream
IndexWriter
) use this method to advance the stream to
the next token. Implementing classes must implement this method and update
the appropriate AttributeImpl
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)
and AttributeSource.getAttribute(Class)
,
references to all AttributeImpl
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()
.
incrementToken
in class TokenStream
java.io.IOException
private void setCurrentToken(Token token)
private Token getNextPrefixInputToken(Token token) throws java.io.IOException
java.io.IOException
private Token getNextSuffixInputToken(Token token) throws java.io.IOException
java.io.IOException
public Token updateSuffixToken(Token suffixToken, Token lastPrefixToken)
suffixToken
- a token from the suffix streamlastPrefixToken
- the last token from the prefix streampublic void end() throws java.io.IOException
TokenStream
TokenStream.incrementToken()
returned false
(using the new TokenStream
API). Streams implementing the old API
should upgrade to use this feature.
This method can be used to perform any end-of-stream operations, such as setting the final offset of a stream. The final offset of a stream might differ from the offset of the last token eg in case one or more whitespaces followed after the last token, but a WhitespaceTokenizer was used.
Additionally any skipped positions (such as those removed by a stopfilter) can be applied to the position increment, or any adjustment of other attributes where the end-of-stream value may be important.
If you override this method, always call super.end()
.
end
in class TokenStream
java.io.IOException
- If an I/O error occurspublic void close() throws java.io.IOException
TokenStream
If you override this method, always call super.close()
, otherwise
some internal state will not be correctly reset (e.g., Tokenizer
will
throw IllegalStateException
on reuse).
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class TokenStream
java.io.IOException
public void reset() throws java.io.IOException
TokenStream
TokenStream.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
throw IllegalStateException
on further usage).
reset
in class TokenStream
java.io.IOException
public TokenStream getPrefix()
public void setPrefix(TokenStream prefix)
public TokenStream getSuffix()
public void setSuffix(TokenStream suffix)