转载请注明出处:http://blog.csdn.net/l1028386804/article/details/49512203
不多说,不废话,直接上代码
public void testAnalyzer(Analyzer analyzer,String text)throws Exception{
System.out.println(analyzer.getClass().getSimpleName());
TokenStream tokenStream= analyzer.tokenStream("content", new StringReader(text));
tokenStream.addAttribute(TermAttribute.class);
while(tokenStream.incrementToken()){
TermAttribute termAttribute=tokenStream.getAttribute(TermAttribute.class);
System.out.println(termAttribute.term());
}
System.out.println();
}