转义Solr中的特殊字符

rdlzhqv9  于 2022-11-05  发布在  Solr
关注(0)|答案(1)|浏览(195)

在Solr中运行http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:"Toys \& Games "此查询后,在转义特殊字符'&'时出现以下错误

{
"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"],

类别字段的类型为字符串多值=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 ',如何通过正确转义特殊字符'&'来实现此目的

afdcj2ne

afdcj2ne1#

您需要对一些字符进行编码。例如以下命令:

$ 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"。请注意:"、空格和&字符是如何编码的。

相关问题