通過分析的令牌手動迭代
TokenStream stream = myAnalyzer.tokenStream("myField", textToAnalyze);
stream.addAttribute(CharTermAttribute.class);
stream.reset();
while(stream.incrementToken()) {
CharTermAttribute token = stream.getAttribute(CharTermAttribute.class);
System.out.println(token.toString());
}
stream.close();
有許多屬性可用。最常見的是 CharTermAttribute
,用於將分析的術語作為字串。