转义特殊字符和编码不安全和保留字符 Lucene 查询语法 Azure 搜索
Escaping special characters & Encoding unsafe and reserved characters Lucene query syntax Azure Search
我在 index
的 azure search 中有单词 "C&&K"、"So`am`I"、"Ant||Man"、"A*B==AB"、"Ant+Man"。
根据 Doc 转义特殊字符 + - && || ! ( ) { } [ ] ^ " ~ * ? : \ /
我需要在它们前面加上反斜杠 (\) 对于不安全和保留的字符需要在 URL 中对它们进行编码。
对于 "C&&K" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%5C%26K~&queryType=full
对于 "So`am`I" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%5C%60am%5C%60I~&queryType=full
对于 "Ant||Man" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
对于 "A*B==AB" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
对于 "Ant+Man" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=Ant%5C%2BMan~&queryType=full
对于所有这些,我都没有得到搜索结果。我得到 "value": []
对于"C&&K"我也试过
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%26K~&queryType=full
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%26%5C%26K~&queryType=full
对于"So`am`I"我也试过
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%60am%60I~&queryType=full
它不起作用。我在这里做错了什么?
通过标准分析,所有这些都将被索引为多个术语。但是,不分析模糊查询,因此它会尝试将其作为单个术语来查找。也就是说,当你索引 "Ant||Man" 时,经过分析,你最终会在索引中得到 "ant" 和 "man" 这两个词。当您搜索 Ant||Man
时,它会以与索引时相同的方式对其进行分析,但是当搜索 Ant||Man~
时,不会分析该查询,因为在索引,你不会得到任何匹配项。同样,对于 "A*B==AB",您会得到术语 "b" 和 "ab"("a" 是默认分析的停用词)。
因此,尝试不带 ~
的查询。
除了 femtoRgon 的响应之外,如果您希望它们始终按原样进行搜索,您可能还需要考虑使用不将这些作为多个术语编制索引的自定义分析器。有 documentation on custom analyzers here, and you can use the Analyze API 需要测试以确保给定的分析器按您预期的方式工作。
我在 index
的 azure search 中有单词 "C&&K"、"So`am`I"、"Ant||Man"、"A*B==AB"、"Ant+Man"。
根据 Doc 转义特殊字符 + - && || ! ( ) { } [ ] ^ " ~ * ? : \ /
我需要在它们前面加上反斜杠 (\) 对于不安全和保留的字符需要在 URL 中对它们进行编码。
对于 "C&&K" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%5C%26K~&queryType=full
对于 "So`am`I" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%5C%60am%5C%60I~&queryType=full
对于 "Ant||Man" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
对于 "A*B==AB" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
对于 "Ant+Man" 我的搜索 url => /indexes/{index-name}/docs?api-version=2017-11-11&search=Ant%5C%2BMan~&queryType=full
对于所有这些,我都没有得到搜索结果。我得到 "value": []
对于"C&&K"我也试过
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%26K~&queryType=full
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%26%5C%26K~&queryType=full
对于"So`am`I"我也试过
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%60am%60I~&queryType=full
它不起作用。我在这里做错了什么?
通过标准分析,所有这些都将被索引为多个术语。但是,不分析模糊查询,因此它会尝试将其作为单个术语来查找。也就是说,当你索引 "Ant||Man" 时,经过分析,你最终会在索引中得到 "ant" 和 "man" 这两个词。当您搜索 Ant||Man
时,它会以与索引时相同的方式对其进行分析,但是当搜索 Ant||Man~
时,不会分析该查询,因为在索引,你不会得到任何匹配项。同样,对于 "A*B==AB",您会得到术语 "b" 和 "ab"("a" 是默认分析的停用词)。
因此,尝试不带 ~
的查询。
除了 femtoRgon 的响应之外,如果您希望它们始终按原样进行搜索,您可能还需要考虑使用不将这些作为多个术语编制索引的自定义分析器。有 documentation on custom analyzers here, and you can use the Analyze API 需要测试以确保给定的分析器按您预期的方式工作。