在 Solr 中转义特殊字符
Escape Special Character In Solr
在 运行 http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:"Toys \& Games "
之后转义特殊字符 '&' 时出现以下错误
Solr 中的这个查询
{
"responseHeader": {
"zkConnected": true,
"status": 400,
"QTime": 0,
"params": {
"q": "*:*",
"Games \"": "",
"fq": "Category:\"Toys \",
"rows": "70"
}
},
"error": {
"metadata": [
"error-class", "org.apache.solr.common.SolrException",
"root-error-class", "org.apache.solr.parser.TokenMgrError"
],
"msg": "org.apache.solr.search.SyntaxError: Cannot parse 'Category:\"Toys \': Lexical error at line 1, column 17. Encountered: <EOF> after : \"\\"Toys \\\"",
"code": 400
}}
类别字段包含如下值
"Category":["Toys & Games "," Learning & Education "," Science Kits & Toys"]
"Category":["Home & Kitchen "," Home Décor "," Window Treatments "," Window Stickers & Films ", " Window Films"],
并且类别字段的类型为 string 且 multivalued=true
{
"name":"Category",
"type":"string",
"multiValued":true,
"stored":true},
如何正确搜索类别:“玩具和游戏”
注意:我尝试了 http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:Toys* AND *"Games "&rows=70
这个查询并且它工作正常,但是如果我非常想搜索字符串 'Toys & Games ' 如何通过正确转义特殊字符 '&'
您需要对某些字符进行编码。例如下面的命令:
$ curl 'http://localhost:8983/solr/puldata/select?fq=title_t%3A%22Woody%20Herman%20%26%20His%20Orchestra%22&q=*&start=0'
将查询 fq=title_t:"Woody Herman & His Orchestra"
。注意 :
、"
、空格和 &
字符是如何编码的。
在 运行 http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:"Toys \& Games "
之后转义特殊字符 '&' 时出现以下错误
Solr 中的这个查询
{
"responseHeader": {
"zkConnected": true,
"status": 400,
"QTime": 0,
"params": {
"q": "*:*",
"Games \"": "",
"fq": "Category:\"Toys \",
"rows": "70"
}
},
"error": {
"metadata": [
"error-class", "org.apache.solr.common.SolrException",
"root-error-class", "org.apache.solr.parser.TokenMgrError"
],
"msg": "org.apache.solr.search.SyntaxError: Cannot parse 'Category:\"Toys \': Lexical error at line 1, column 17. Encountered: <EOF> after : \"\\"Toys \\\"",
"code": 400
}}
类别字段包含如下值
"Category":["Toys & Games "," Learning & Education "," Science Kits & Toys"]
"Category":["Home & Kitchen "," Home Décor "," Window Treatments "," Window Stickers & Films ", " Window Films"],
并且类别字段的类型为 string 且 multivalued=true
{
"name":"Category",
"type":"string",
"multiValued":true,
"stored":true},
如何正确搜索类别:“玩具和游戏”
注意:我尝试了 http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:Toys* AND *"Games "&rows=70
这个查询并且它工作正常,但是如果我非常想搜索字符串 'Toys & Games ' 如何通过正确转义特殊字符 '&'
您需要对某些字符进行编码。例如下面的命令:
$ curl 'http://localhost:8983/solr/puldata/select?fq=title_t%3A%22Woody%20Herman%20%26%20His%20Orchestra%22&q=*&start=0'
将查询 fq=title_t:"Woody Herman & His Orchestra"
。注意 :
、"
、空格和 &
字符是如何编码的。