Lucene.Net最高版本为3.0.3,并且apache已经不再提供Lucene.Net的更新,没仔细研究过Lucene.Net的所有版本,Lucene.Net3.0.3遍历TokenStream获取Token对象,已经和以前的版本有了很大的区别,很多方法都已经删除了或者过时。
 以前版本的Lucene.Net从TokenStream中获取Token时调用Next方法就行了,源代码如下

public void ReusableTokenStream2()
{
string testwords = "web开发网";
SimpleAnalyzer simple = new SimpleAnalyzer();
TokenStream ts = simple.ReusableTokenStream("", new StringReader(testwords));
Token token;
while ((token = ts.Next()) != null)
{
Console.WriteLine(token.TermText());
}
ts.Close();
}

  但是在Lucene.Net3.0.3中TokenStream已经不存在Next方法,而是需要ITermAttribute属性接口来遍历。源代码如下

  public void ReusableTokenStream3()
{
Lucene.Net.Analysis.Standard.StandardAnalyzer a = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
string s = "web开发网";
System.IO.StringReader reader = new System.IO.StringReader(s);
Lucene.Net.Analysis.TokenStream ts = a.TokenStream(s, reader);
bool hasnext = ts.IncrementToken();
Lucene.Net.Analysis.Tokenattributes.ITermAttribute ita;
while (hasnext)
{
ita = ts.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();
Console.WriteLine(ita.Term);
hasnext = ts.IncrementToken();
}
ts.CloneAttributes();
reader.Close();
a.Close();
Console.ReadKey();
}

Lucene.Net 3.0.3如何从TokenStream中获取token对象的更多相关文章

  1. ASP.NET WebApi OWIN 实现 OAuth 2.0(自定义获取 Token)

    相关文章:ASP.NET WebApi OWIN 实现 OAuth 2.0 之前的项目实现,Token 放在请求头的 Headers 里面,类似于这样: Accept: application/jso ...

  2. lucene.net 3.0.3、结合盘古分词进行搜索的小例子(转)

    lucene.net 3.0.3.结合盘古分词进行搜索的小例子(分页功能)   添加:2013-12-25 更新:2013-12-26 新增分页功能. 更新:2013-12-27 新增按分类查询功能, ...

  3. IKAnalyzer兼容Lucene 5.4.0版本抛出异常?

    ava.lang.AbstractMethodError: org.apache.lucene.analysis.Analyzer.createComponents(Ljava/lang/String ...

  4. 让盘古分词支持最新的Lucene.Net 3.0.3

    原文:让盘古分词支持最新的Lucene.Net 3.0.3 好多年没升级过的Lucene.Net最近居然升级了,到了3.0.3后接口发生了很大变化,原来好多分词库都不能用了,所以上次我把MMSeg给修 ...

  5. Lucene 6.5.0 入门Demo

    Lucene 6.5.0 要求jdk 1.8 1.目录结构: 2.数据库环境: private int id; private String name; private float price; pr ...

  6. Lucene 4.6.1 java.lang.IllegalStateException: TokenStream contract violation

    这是旧代码在新版本Lucene中出现的异常,异常如下: Exception in thread "main" java.lang.IllegalStateException: To ...

  7. Lucene中的 Query对象

    "Lucene中的 Query对象": 检 索前,需要对检索字符串进行分析,这是由queryparser来完成的.为了保证查询的正确性,最好用创建索引文件时同样的分析器. quer ...

  8. HDFS(0.20.2)运营中急救方案

    这段时间折腾的都是hadoop和lucene,总结了hadoop在运营过程中出现问题时的解决方案,请大家指教! HDFS(0.20.2)运营中急救方案 1           Namenode 挂掉( ...

  9. vue-router2.0 组件之间传参及获取动态参数

    <li v-for=" el in hotLins" > <router-link :to="{path:'details',query: {id:el ...

随机推荐

  1. [Docker]——container和主机(host)之间的文件拷贝

    1. 从 container 到 主机(host) 使用 docker cp 命令 docker cp <containerId>:/file/path/within/container ...

  2. centos6.6-6.8的cobbler的kickstarts文件

    author:headsen chendate: 2018-07-10 19:14:39 1,普通的mbr版的kickstarts的配置文件: [root@cobbler-server ~]# cat ...

  3. 01.ZooKeeper安装和介绍

    1.ZooKeeper安装和启动 1.下载解压ZooKeeper ZooKeeper官方地址:http://zookeeper.apache.org/ 下载当前稳定版本:zookeeper-3.4.6 ...

  4. Android开源天气预报应用Weather-Lite

    由于最近繁忙的工作告一段落,要清闲一段时间,所以可以好好利用这段时间给自己充充电. 于是乎这个app就诞生了.本着开源的精神我把它放在了github上.这里如果有Android初学者的话不妨学习一下, ...

  5. python--excel

    import xlrd, xlwt # 读取Exceldef read_excel(excel_name, sheet_name): if excel_name and excel_name: all ...

  6. textarea文本输入区内实现换行

    在文本间输入 即可成功换行 <textarea class="mytextarea">1.第一行 2.第二行 </textarea>

  7. python console

    print(sys.stdout.encoding, locale.getpreferredencoding ()) windows console : chcp 65001; 在设置了这个环境变量时 ...

  8. BitTrex行情查看与技术指标系统

    上个月的时候,向TradingView申请K线图行情插件,填了各种资料,被问了N多问题,结果却仍是不愿意提供插件给我们. 于是,我们自己开发了一个BitTre行情查看与技术指标系统, 这套系统被国内多 ...

  9. https://zh.cppreference.com 和 https://en.cppreference.com 和 https://cppcon.org/

    https://zh.cppreference.comhttps://en.cppreference.com/w/ https://cppcon.org/

  10. 使用LoadRunner的Web(HTTP/HTML)协议录制手机app脚本

    一.打开HP Virtual User Generator,创建虚拟用户脚本,选择Web(HTTP/HTML)协议: