现象:

org.apache.lucene.queryParser.ParseException: Encountered "<EOF>" at line 1, column 0.
Was expecting one of:<NOT> ..."+" ..."-" ..."(" ...<QUOTED> ...<TERM> ...<PREFIXTERM> ...<WILDTERM> ..."[" ..."{" ...<NUMBER> ...at org.apache.lucene.queryParser.QueryParser.generateParseException(QueryParser.java:1226)
at org.apache.lucene.queryParser.QueryParser.jj_consume_token(QueryParser.java:1109)
at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:759)
at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:684)
at ch2.lucenedemo.process.Test.RunVsIndex(Test.java:142)
at ch2.lucenedemo.process.Test.main(Test.java:169)

方法一:

如果出现了下列错误,那是因为用错了函数。把queryParser.Query改称queryParser.parse就通过了

方法二:

1、提问:

I am working on a classification problem to classify product reviews as positive, negative or neutral as per the training data using Lucene API.

I am using an ArrayList of Review objects - "reviewList" that stores the attributes for each review while crawling the web pages.

The review attributes which include "polarity" & "review content" are then indexed using the indexer. Thereafter, based on the indexes objects, I need to classify the remaining review objects. But while doing so, there is a review object for which the Query parser is encountering an EOF character in the "review content", and hence terminating.

The line causing error has been commented accordingly -

IndexReader reader = IndexReader.open(FSDirectory.open(new File("index")));IndexSearcher searcher = new IndexSearcher(reader);Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);QueryParser parser = new QueryParser(Version.LUCENE_31, "Review", analyzer);int length = Crawler.reviewList.size();for (int i = 200; i < length; i++) {String true_class;double r_stars = Crawler.reviewList.get(i).getStars();if (r_stars < 2.0) {true_class = "-1";} else if (r_stars > 3.0) {true_class = "1";} else {true_class = "0";}String[] reviewTokens = Crawler.reviewList.get(i).getReview().split(" ");String parsedReview = "";int j;for (j = 0; j < reviewTokens.length; j++) {if (reviewTokens[j] != null) {if (!((reviewTokens[j].contains("-")) || (reviewTokens[j].contains("!")))) {parsedReview += reviewTokens[j] + " ";}} else {break;}}Query query = parser.parse(parsedReview); // CAUSING ERROR!!TopScoreDocCollector results = TopScoreDocCollector.create(5, true);searcher.search(query, results);ScoreDoc[] hits = results.topDocs().scoreDocs;

I've parsed the text manually to remove the characters that are causing the error, apart from checking if the next string is null...but the error persists.

This is the error stack trace -

Exception in thread "main" org.apache.lucene.queryParser.ParseException: Cannot parse 'I made the choice ... be all "thumbs ': Lexical error at line 1, column 938.  Encountered: <EOF> after : "\"thumbs "
at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:216)
at Sentiment_Analysis.Classification.classify(Classification.java:58)
at Sentiment_Analysis.Main.main(Main.java:17)
Caused by: org.apache.lucene.queryParser.TokenMgrError: Lexical error at line 1, column 938.  Encountered: <EOF> after : "\"thumbs "
at org.apache.lucene.queryParser.QueryParserTokenManager.getNextToken(QueryParserTokenManager.java:1229)
at org.apache.lucene.queryParser.QueryParser.jj_scan_token(QueryParser.java:1709)
at org.apache.lucene.queryParser.QueryParser.jj_3R_2(QueryParser.java:1598)
at org.apache.lucene.queryParser.QueryParser.jj_3_1(QueryParser.java:1605)
at org.apache.lucene.queryParser.QueryParser.jj_2_1(QueryParser.java:1585)
at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1280)
at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1266)
at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1313)
at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1266)
at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1226)
at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:206)
... 2 more
Java Result: 1

Please help me solve this problem...have been banging my head with this for hours now!

2、问答

You should escape the double quote and other special characters via

Query query = parser.parse(QueryParser.escape(parsedReview));

As the QueryParser.escape Javadoc suggested,

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding '\'.

小结:使用 QueryParser的静态方法QueryParser.escape(string s),进行自动转义特殊字符后再进行关键字的查询

原文出处:

现象及方法一:

不设限, org.apache.lucene.queryParser.ParseException: Encountered "<EOF>" at line 1, column 0. https://blog.csdn.net/tengdazhang770960436/article/details/17881671

方法二:

https://stackoverflow.com/questions/10259907/lucene-exception-query-parser-encountered-eof-after-some-word

转载于:https://www.cnblogs.com/ryelqy/p/10104041.html

关于org.apache.lucene.queryParser.ParseException: Encountered 解决方法相关推荐

  1. 利用宝塔 开启apache tomcat ssl 失败的解决方法

    利用宝塔 开启apache tomcat ssl 失败的解决方法 参考文章: (1)利用宝塔 开启apache tomcat ssl 失败的解决方法 (2)https://www.cnblogs.co ...

  2. HttpRequestException encountered解决方法

    HttpRequestException encountered解决方法 参考文章: (1)HttpRequestException encountered解决方法 (2)https://www.cn ...

  3. xampp中apache点击启动失败解决方法

    xampp中apache点击启动失败解决方法 参考文章: (1)xampp中apache点击启动失败解决方法 (2)https://www.cnblogs.com/cuisaihang/p/70088 ...

  4. EXP-00056: ORACLE error 12514 encountered解决方法

    EXP-00056: ORACLE error 12514 encountered解决方法 oracle10g环境下导出: 1 exp parfile=exp3.txt 2.exp3.txt内容USE ...

  5. Apache shutdown unexpectedly启动错误解决方法

    转载地址:http://blog.csdn.net/dong123dddd/article/details/21372179 xampp启动时显示的错误为: 9:52:41  [Apache] Att ...

  6. mybatis org.apache.ibatis.ognl.ParseException: Encountered “ <IDENT> “AND ““ at line 1, column 14.

    mybatis中if判断的and 要小写,大写报错的原因 <if test="(personName != null and personName!='') || (companyNa ...

  7. sql报错,org.apache.ibatis.ognl.ParseException: Encountered “ <IDENT> “AND ““

    在一个风和日丽的下午,我照常写着代码,但是在一次自测接口时,发现了一个报错.提示如下: 当时有点懵. <select id="selectCompanySample"> ...

  8. phpnow安装apache失败及phpnow绑定域名解决方法,网站发布到外网

    在使用PHPnow工具安装Apache和MySQL数据库时经常会出现以下错误信息: 安装服务 [apache_pn]失败.可能原因如下: 1. 服务名已存在,请卸载或使用不同的服务名. 2. 非管理员 ...

  9. 虚拟主机用户ftp和apache用户文件互操作权限解决方法

    方法1.用户组控制方法 先给所有的虚拟主机主机中的虚拟用户(ftp用户)加入到apache这个组.然后设置umask为002.这样用户和组都有读写执行权限.这个是比较容易的方法.但不安全.不同的用户可 ...

最新文章

  1. 50 xen虚拟化技术基础、xen虚拟化技术进阶
  2. 烧录imx6需要的linux空间,IMX6Q学习笔记——开发板的Linux系统更新和烧录
  3. Spring cloud Loadbalance
  4. 二元置信椭圆r语言_医学统计与R语言:圆形树状图(circular dendrogram)
  5. 应对全场景AI框架部署挑战,MindSpore“四招”让你躺平
  6. 由需求而产生的一款db导出excel的工具
  7. 腾讯正式开源高性能Hybrid框架VasSonic!
  8. Android7.1 Audio Debug相关方法
  9. setuna截图怎么放大缩小_一款强大的电脑截图神器,快速提高工作效率,功能强大!...
  10. office for mac的字体设置
  11. 假设检验-统计学自学笔记
  12. Mac电脑快速查找文件的两种方法
  13. 用计算机找到自己的另一半,如何找到自己的另一半
  14. pandoc 转换html,pandoc将markdown转换输出HTML slide
  15. vue datepicker 动态控制时分秒 当前时间以后可选
  16. 写给 Linux 初学者的一封信
  17. kubeadm join时报错Unauthorized
  18. 直线回归和相关------(二)直线回归的假设测验和区间估计以及matlab实现
  19. Echarts桑基图sankey点击高亮显示
  20. ChatGPT的使用学习笔记

热门文章

  1. Spring和Mybatis集成,如何批量insert update?以及一些通用Dao的设想
  2. 【应用笔记】【AN001】VC#开发环境下基于以太网的4-20mA电流采集(基于modbus tcp 协议)...
  3. NET中的异步编程(二)- 传统的异步编程
  4. JS设计模式—节流模式的实际应用
  5. 想客户之所想 华为全栈云加速行业云化创新
  6. JS高级 - 面向对象5(继承,引用)
  7. 存储过程系列之调试存储过程 SQL Server 2005
  8. Navicat是如何连接到服务器的呢
  9. js获取本月第几周和本年第几周
  10. HTML 5 令人期待的 5 项功能