使用Lucene 3.0.0的结构遍历TokenStream的内容.

    以前版本的Lucene是用TokenStream.next()来遍历TokenStream的内容, 目前的版本稍微修改了一下, 使用下面的的一段程序可以遍历TokenStream的内容

private static void displayTokenStream(TokenStream ts) throws IOException
{
  TermAttribute termAtt = (TermAttribute)ts.getAttribute(TermAttribute.class);
  TypeAttribute typeAtt = (TypeAttribute)ts.getAttribute(TypeAttribute.class);
  
  while (ts.incrementToken())
  {
      System.out.print(termAtt.term());
      System.out.print(' ');
      System.out.println(typeAtt.type());
  }
  System.out.println(' ');
}
posted @ 2010-01-14 15:17  LeftNotEasy  阅读(5290)  评论(1编辑  收藏  举报