lucene3.0分词结果显示
lucene3.0升级后,以前的显示分词结果的语句完全不能用了,我们选择分词器又是必须的,到底我们的关键词分词后是怎么显示的呢,具体代码如下:
- public class AnalyzerTest {
- public static void main(String[] args) throws IOException {
- String content = "亲亲宝宝";
- // String content = "亲亲宝宝网站, lucene3.0分词结果测试";
- // String content = " lucene3.0升级后,以前的显示分词结果的语句完全不能用了,我们选择分词器是必须的,具体代码如下";
- StringReader reader = new StringReader(content);
- Analyzer analyzer = null;
- analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
- TokenStream ts = analyzer.tokenStream("test", reader);
- ts.addAttribute(TermAttribute.class);
- while (ts.incrementToken()) {
- TermAttribute ta = ts.getAttribute(TermAttribute.class);
- System.out.println(ta.term());
- }
- }
- }
欢迎转载,请注明出处:亲亲宝宝