Azure 认知搜索 - 匹配某些字段的精确短语

Azure Cognitive Search - match exact phrase for some fields

我的 Azure 认知搜索中有不同的字段,但让我向您展示一些我遇到问题的字段。

{
   "name": "Name",
   "type": "Edm.String",
   "searchable": true,
   "filterable": false,
   "retrievable": true,
   "sortable": true,
   "facetable": false,
   "key": false,
   "indexAnalyzer": null,
   "searchAnalyzer": null,
   "analyzer": "standard.lucene",
   "synonymMaps": []
}

{
    "name": "Code",
    "type": "Edm.String",
    "searchable": true,
    "filterable": false,
    "retrievable": true,
    "sortable": false,
    "facetable": false,
    "key": false,
    "indexAnalyzer": null,
    "searchAnalyzer": null,
    "analyzer": "keyword",
    "synonymMaps": []
}

正如您在上面看到的,我为名称设置了分析器 standard.lucene(我为其他字段设置了特定语言,例如 NameEn),为代码字段设置了关键字分析器。

例如,当我按 1-1 搜索时,它会查找 1 而不是 1-1。我尝试使用双引号,但似乎我也不起作用 ("1-1")。

问题是结果我得到的名称是数字 1,而不是代码是 1-1。

你知道我该怎么做吗?我想我应该搜索整个短语,例如:“1-1”查询的其余部分。

当您发送查询时,所有可搜索字段的分析器都会对其进行分析,然后将针对所有这些字段执行标记化查询(每个字段不同)。

您可以将查询发送到 analyze 端点以调试每个分析器如何处理您的查询 - https://serviceName.search.windows.net/indexes/index-name/analyze?api-version=2020-06-30

你的情况:

{
    "text": "1-1",
    "analyzer": "standard"
}

returns Name 字段的这些标记

 "tokens": [
        {
            "token": "1",
            "startOffset": 0,
            "endOffset": 1,
            "position": 0
        },
        {
            "token": "1",
            "startOffset": 2,
            "endOffset": 3,
            "position": 1
        }
    ]

Code 字段

{
    "text": "1-1",
    "analyzer": "keyword"
}

你得到

"tokens": [
        {
            "token": "1-1",
            "startOffset": 0,
            "endOffset": 3,
            "position": 0
        }
    ]

所以对于这样的查询,您实际上是在寻找

的文档

Name=1 | Code=1-1

如果您只想在选定的字段中搜索,您可以使用 searchFields 参数指定它们。