解析查询时出现Lucene错误:无法解析":遇到“< EOF>"在第1行,第0列 [英] Lucene error while parsing Query: Cannot parse '': Encountered "<EOF>" at line 1, column 0

查看:482
本文介绍了解析查询时出现Lucene错误:无法解析":遇到“< EOF>"在第1行,第0列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Lucene查询解析器解析一些文本,以对文本进行基本的文本预处理.我使用了以下代码行:

I want to parse some text using Lucene query parser to carry out basic text preprocessing on the texts. I used following lines of code:

Analyzer analyzer = new EnglishAnalyzer();
QueryParser parser = new QueryParser("", analyzer);
String text = "...";
String ret = parser.parse(QueryParser.escape(text)).toString();

但是,我收到一个错误消息:

But, I am getting an error:

Exception in thread "main" org.apache.lucene.queryparser.classic.ParseException: Cannot parse '': Encountered "<EOF>" at line 1, column 0.

推荐答案

使用Query.escape()会删除特殊字符.但是它不会删除

Using Query.escape() removes the special characters. However it doesn't remove

与,非或

是在lucene搜索中使用的关键字.

which are keywords used in lucene search.

有两种处理方法:

  1. 在查询字符串中替换AND,NOT或OR.
  2. 将查询字符串转换为小写.

转换为小写字母可以解决此问题,因为只有大写的AND,NOT或OR是关键字.它们被视为小写的普通单词.

Converting to lower case resolves the issue as only the capitalized AND, NOT, OR are keywords. They are treated as a regular word in lower case.

这篇关于解析查询时出现Lucene错误:无法解析":遇到“&lt; EOF&gt;"在第1行,第0列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆