| org.apache.solr.analysis.BufferedTokenStream
All known Subclasses: org.apache.solr.analysis.RemoveDuplicatesTokenFilter,
BufferedTokenStream | abstract public class BufferedTokenStream extends TokenStream (Code) | | Handles input and output buffering of TokenStream
// Example of a class implementing the rule "A" "B" => "Q" "B"
class MyTokenStream extends BufferedTokenStream {
public MyTokenStream(TokenStream input) {super(input);}
protected Token process(Token t) throws IOException {
if ("A".equals(t.termText())) {
Token t2 = read();
if (t2!=null && "B".equals(t2.termText())) t.setTermText("Q");
if (t2!=null) pushBack(t2);
}
return t;
}
}
// Example of a class implementing "A" "B" => "A" "A" "B"
class MyTokenStream extends BufferedTokenStream {
public MyTokenStream(TokenStream input) {super(input);}
protected Token process(Token t) throws IOException {
if ("A".equals(t.termText()) && "B".equals(peek(1).termText()))
write(t);
return t;
}
}
author: yonik version: $Id$ |
Method Summary | |
final public Token | next() | protected Iterable<Token> | output() Provides direct Iterator access to the buffered output stream. | protected Token | peek(int n) Peek n tokens ahead in the buffered input stream, without modifying
the stream. | abstract protected Token | process(Token t) Process a token. | protected void | pushBack(Token t) | protected Token | read() Read a token from the buffered input stream. | protected void | write(Token t) |
BufferedTokenStream | public BufferedTokenStream(TokenStream input)(Code) | | |
output | protected Iterable<Token> output()(Code) | | Provides direct Iterator access to the buffered output stream.
Modifying any token in this Iterator will affect the resulting stream.
|
peek | protected Token peek(int n) throws IOException(Code) | | Peek n tokens ahead in the buffered input stream, without modifying
the stream.
Parameters: n - Number of tokens into the input stream to peek, 1 based ...0 is invalid a Token which exists in the input stream, any modificationsmade to this Token will be "real" if/when the Token isread() from the stream. |
process | abstract protected Token process(Token t) throws IOException(Code) | | Process a token. Subclasses may read more tokens from the input stream,
write more tokens to the output stream, or simply return the next token
to be output. Subclasses may return null if the token is to be dropped.
If a subclass writes tokens to the output stream and returns a
non-null Token, the returned Token is considered to be at the head of
the token output stream.
|
pushBack | protected void pushBack(Token t)(Code) | | Push a token back into the buffered input stream, such that it will
be returned by a future call to read()
|
read | protected Token read() throws IOException(Code) | | Read a token from the buffered input stream.
null at EOS |
write | protected void write(Token t)(Code) | | Write a token to the buffered output stream
|
|
|