且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用QueryParser执行包含特殊字符的lucene查询?

更新时间:2021-11-04 08:24:25

我不确定这一点,但我想你需要使用 \ 逃避 - 。根据 Lucene docs

I am not sure about this , but I guess you need to escape - with \ . As per the Lucene docs.


- 或禁止运算符排除包含 - 符号后面的术语的文档。

The "-" or prohibit operator excludes documents that contain the term after the "-" symbol.

再次,


Lucene支持转义特殊字符是查询语法的一部分。当前列表中的特殊字符是

Lucene supports escaping special characters that are part of the query syntax. The current list special characters are

+ - && || ! (){} [] ^〜*?:\ /

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

要转义这些字符,请在字符前使用\。

To escape these character use the \ before the character.

还要记住,如果它们在Java中有特殊含义,你需要转义两次。

Also remember, some characters you'll need to escape twice if they have special meaning in Java.