例:lucene 的同义词分析器
package player.kent.chen.temp.lucene.synonymon; import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.Queue; import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.tokenattributes.TermAttribute; import org.apache.lucene.util.AttributeSource; public class MySynonymFilter extends TokenFilter { private final TermAttribute termAttr; private final PositionIncrementAttribute piAttr; private final Queue<String> synonyms = new LinkedList<String>(); private AttributeSource.State attrsState; protected MySynonymFilter(TokenStream input) { super(input); this.piAttr = addAttribute(PositionIncrementAttribute.class); this.termAttr = addAttribute(TermAttribute.class); …