我们已将文档存储到 azure 搜索中。其中一个文档具有以下字段值。
“Title”:“statistics_query.compute_shader_invocations.secondary_inherited 失败”
我们根据 MS Azure 团队的建议定义了自定义分析器,以解决我们因 _(下划线)而面临的问题之一。
{
"name": "myindex",
"fields": [
{
"name": "id",
"type": "Edm.String",
"searchable": true,
"filterable": true,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": true,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": null
},
{
"name": "Title",
"type": "Edm.String",
"searchable": true,
"filterable": true,
"retrievable": true,
"sortable": true,
"facetable": true,
"key": false,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": "remove_underscore"
}
],
"analyzers": [
{
"name": "remove_underscore",
"@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
"charFilters": [
"remove_underscore"
],
"tokenizer": "standard_v2"
}
],
"charFilters": [
{
"name": "remove_underscore",
"@odata.type": "#Microsoft.Azure.Search.MappingCharFilter",
"mappings": [
"_=>-"
]
}
]
}
但是,当我在我的 azure 搜索索引(版本号 2016-09-01 预览版)上使用以下过滤器进行搜索时,我没有得到任何结果。
$filter=search.ismatch('"compute_shader_in Vocations*"','标题','完整','任意')
$filter=search.ismatch('"compute_shader_invocates"','标题','完整','任意')
$filter=search.ismatch('"shader_in Vocations*"','标题','完整','任意')
但是,如果我包含带有 (.) 点字符的文本,则相同的过滤器将起作用。
$filter=search.ismatch('"query.compute_shader*"','标题','完整','任意')
根据我的测试,如果文档在过滤器中使用的搜索词之后或之前存在点 (.) 字符,则搜索不会返回结果。
因此,下面的过滤器将不起作用,因为文档中在查询中使用的搜索词之前和之后存在一个 (.) 点字符。在我们的示例中,Azure 搜索文档中的单词“compute”之前和单词“incalls”之后有一个点字符。
$filter=search.ismatch('"compute_shader_in Vocations*"','标题','完整','任意')
$filter=search.ismatch('"compute_shader"','标题','完整','任意')
$filter=search.ismatch('"shader_in Vocations*"','标题','完整','任意')
但是,下面的过滤器应该可以工作,因为在 Azure 搜索文档中,单词“query”之前或单词“shadder”之后没有点字符
$filter=search.ismatch('"query.compute_shader*"','标题','完整','任意') $filter=search.ismatch('"shader*"','标题','完整','任意')
这让我发疯。任何帮助将不胜感激。
最佳答案
tl;dr 通配符查询不执行自定义分析。非通配符查询应返回结果,因此请仔细检查
详细解答
所以,点 (.) 实际上与您正在观察的行为没有任何关系。您发出的搜索查询有 2 类:
- 通配符查询
*
- 非通配符查询(例如“compute_shader”)
一般来说,您发出的非通配符查询将经历与索引中任何自定义分析器定义的分析相同的分析。如果是通配符查询,则不执行任何分析。
现在以您的文档文本为例“statistics_query.compute_shader_invocations.secondary_inherited 失败”,您定义的自定义分析器会将其分解为标记。 (仅供引用:您可以使用 Analyze API 查看详细信息)。
以下通配符查询成功
$filter=search.ismatch('"shader*"','Title', 'full', 'any')
因为,当您对源文档运行分析时,会出现诸如“shader”之类的标记
以下通配符查询不成功
$filter=search.ismatch('"compute_shader_invocations*"','Title', 'full', 'any') $filter=search.ismatch('"shader_invocations*"','Title', 'full', 'any')
因为当使用自定义分析器分析源文档时,不存在诸如“computer_shader_invocals” 或“shader_invocations” 之类的标记。
这个也不应该成功,但有趣的是你说它确实成功了:
$filter=search.ismatch('"query.compute_shader*"','Title', 'full', 'any')
现在让我们关注没有通配符的查询。
$filter=search.ismatch('"compute_shader_invocations"','Title', 'full', 'any') $filter=search.ismatch('"compute_shader"','Title', 'full', 'any')
从技术上讲,这些应该使用自定义分析器正确标记,并且应该具有匹配的结果。
您能否验证一下您在原始问题中最后 3 个突出显示实例中的查询是否正确?当我尝试创建示例索引并根据您的配置发出搜索请求时,我注意到了 3 个异常情况。我希望能对这些问题进行一些澄清。
此外,一般来说 documentation关于 Azure 搜索中全文搜索的工作原理是深入了解我提到的一些内容的好地方。
关于Azure 搜索未返回正确的结果。搜索查询中的(点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48942334/