solr查询特殊字符的处理

1. 使用solr的页面功能时,遇到语法错误

2. 确认原因

从lexical error分析时特殊字符的问题。

首先 solr查询有哪些特殊字符?

查找官方文档:http://lucene.apache.org/core/7_6_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description

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

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

双引号包含在内,故确认原因。

3.解决方式

官方提供了解决方式http://lucene.apache.org/core/7_6_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description

扫描二维码关注公众号,回复: 5677950 查看本文章

To escape these character use the \ before the character. For example to search for (1+1):2 use the query:

\(1\+1\)\:2

4.验证问题

问题解决

5.小结

特殊字符的处理在java solr都会存在,官方文档作为最权威的数据来源,值得我们关注。

猜你喜欢

转载自www.cnblogs.com/davidwang456/p/10605861.html