这是个郁闷的问题,今天遇到了,但在lucene中查询的关键字保护有特殊字符,譬如--,会出现如下异常:
org.apache.lucene.queryParser.ParseException: Cannot parse '': Encountered " <EOF>" at line 1, column 0.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
"(" ...
"*" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
"[" ...
"{" ...
<NUMBER> ...
解决方法:
使用 QueryParser的静态方法escape(string s),进行自动转义特殊字符后再进行关键字的查询
lucene的特殊字符保护了以下的字符:
+ - && || ! ( ) { } [ ] ^ " ~ * ? :