lucene3.0分词结果显示

关键词 :lucene 全文检索

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());                                        
  •               }
  •        }
  • }

    本文链接地址:http://www.wenhq.com/article/view_410.html

  • 你可能感兴趣的:(职场,分词,休闲,结果)