incrementtoken-lucene TokenStream.incrementToken() 报错

问题描述

lucene TokenStream.incrementToken() 报错

初学,在网上找了一些例子例如:CSDN移动问答

然后自己在电脑上跑了一下报错,我的代码

public static void main(String[] args) throws IOException
{
    String s = "Good Afternoon Doesn't IS a good body names NAMES 1,671,000 hy body";
    Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_42);
    TokenStream ts =analyzer.tokenStream(s, new StringReader(s));
    CharTermAttribute cab = ts.addAttribute(CharTermAttribute.class);
    ts.incrementToken();
    /*while(ts.incrementToken())
    {
        System.out.println(cab.toString());
    }*/
}

结果报错:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at java.lang.Character.codePointAtImpl(Unknown Source)
at java.lang.Character.codePointAt(Unknown Source)
at org.apache.lucene.analysis.util.CharacterUtils$Java5CharacterUtils.codePointAt(CharacterUtils.java:164)
at org.apache.lucene.analysis.util.CharTokenizer.incrementToken(CharTokenizer.java:166)
at pim.topicmap.FormatConverter.main(FormatConverter.java:69)

就是这句ts.incrmentToken();求解

解决方案

你看的代码应该是3.5左右的版本;
4之后做了改进,api里和源代码里有说明
The workflow of the new TokenStream API is as follows:

Instantiation of TokenStream/TokenFilters which add/get attributes to/from the AttributeSource.
The consumer calls reset().
The consumer retrieves attributes from the stream and stores local references to all attributes it wants to access.
The consumer calls incrementToken() until it returns false consuming the attributes after each call.
The consumer calls end() so that any end-of-stream operations can be performed.
The consumer calls close() to release any resource when finished using the TokenStream.
To make sure that filters and consumers know which attributes are available, the attributes must be added during instantiation. Filters and consumers are not required to check for availability of attributes in incrementToken().

1.while 之前reset()一下
2.while 之后end()一下
3.然后关闭流

时间: 2024-10-22 02:40:43

incrementtoken-lucene TokenStream.incrementToken() 报错的相关文章

Lucene 多条件查询是用must not报错,请大家看看可能是什么原因

问题描述 Lucene多条件查询是用mustnot报错了,使用must没问题,请大家指点:报错信息:atorg.apache.lucene.util.OpenBitSetDISI.inPlaceAnd(OpenBitSetDISI.java:66)atorg.apache.lucene.search.BooleanFilter.getDocIdSet(BooleanFilter.java:102)atorg.apache.lucene.search.IndexSearcher.searchWit

用64位Juno 64位 SP1环境替换原来的Juno 32位 启动Eclipse报错

64位Eclipse运行时提示"Failed to load the JNI shared library \Java\jre6\bin\client\jvm.dll"的一个解决方案 由于开发环境改变,改用64位Juno 64位 SP1环境替换了原来的Juno 32位.结果启动Eclipse报错: "Failed to load the JNI shared library "E:\2000\Java\JDK6\bin\..jre\bin\client\jvm.dl

bean-该有的包都有了,IDEA下一启动就报错,大家进来给点意见

问题描述 该有的包都有了,IDEA下一启动就报错,大家进来给点意见 2015-7-27 15:18:04 org.apache.catalina.core.ApplicationContext log 严重: StandardWrapper.Throwable java.lang.ExceptionInInitializerError Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Error

报错freemarker.core.NonStringException

问题描述 .out文件报错:18:08:51.030ERRORfreemarker.runtime-Erroronline42,column121inWEB-INF/t/cms/www/red/special/搜索结果页.htmlExpectingastring,dateornumberhere,Expressions.urlisinsteadafreemarker.core.Macrofreemarker.core.NonStringException:Erroronline42,column

$.ajax传JSON数据到后台出现报错问题解决

 $.ajax传JSON数据到后台时总会出现一些错误,本文整理了一些注意事项,感兴趣的朋友可以参考下 代码如下: $.ajax({  url: "../Services.ashx",  type: "POST",  //data: { 'data': { 'typename': JSON.stringify(typename) }, 'operationType': '2' },  data: { 'data': typename, 'operationType':

jdk安装好后,控制台报错如下。

问题描述 jdk安装好后,控制台报错如下. -->java -version -->Error:opening registry key'SofrwareJavaSoftJava Runtime Environment' -->Error:could not find java.dll -->Error:could not find Java SE Runtime Environment 解决方案 环境变量配置好了吗?要不就是你装的JDK有问题. 解决方案二: 是不是没有访问注册表

web service-axis2处理webServices在was环境下报错,tomcat下正常

问题描述 axis2处理webServices在was环境下报错,tomcat下正常 关键代码如下 /** * 申诉请求 */ public static String appealRequest(String requestXML, ImageFileData[] file) { String result = ""; try { // 使用RPC方式调用WebService RPCServiceClient serviceClient = new RPCServiceClient(

Genymoation安装之后打开虚拟机报错求大神指点

问题描述 Genymoation安装之后打开虚拟机报错求大神指点 错误是这样的 求大神指点,谢谢 解决方案 多启动几次,如果还不行,就启动virtualbox,在里面看看对应的虚拟机是否正常可以启动,或者先关掉它

cfbundleidentifier-bundleID 报错怎么解决?

问题描述 bundleID 报错怎么解决? (null): error: CFBundleIdentifier 'com.xxx.xxx-Hmis' contains illegal character '' invalid bundle identifier 'com.xxx.xxx-Hmis' 真机测试遇到这种报错怎么解决? 解决方案 对于这个问题,我自己找到了个解决方案.就是再建一个项目,把之前做的内容加上去,回避了这个问题.但是这个报错的解决办法还是不清楚,求大神解答!!