首页 > 解决方案 > 如何停止 zh-Hans.microsoft 分析器匹配几乎任何东西

问题描述

我无法让 Azure 搜索中的中文语言学正常工作。它出乎意料地匹配几乎任何东西。例如,我有一个最小的测试用例,其中使用 zh-Hans.microsoft 分析器的属性包含以下内容:

米/6克

这将意外匹配M1.6的查询。这怎么可能?即使我的查询将被标记为 M1 和 6,它仍然不应该将我的内容与标记 M 和 6g 匹配?

我测试了 20 种不同的分析仪。它们都不会导致匹配,除非我使用 zh-Hans.microsoft。

最小指数

{
"@odata.context": "https://{{SEARCH_SVC}}.{{DNS_SUFFIX}}/$metadata#indexes/$entity",
"@odata.etag": "\"0x8D8761DCBBCCD00\"",
"name": "products",
"defaultScoringProfile": null,
"fields": [
    {
        "name": "Id",
        "type": "Edm.String",
        "facetable": false,
        "filterable": true,
        "key": true,
        "retrievable": true,
        "searchable": false,
        "sortable": true,
        "analyzer": null,
        "indexAnalyzer": null,
        "searchAnalyzer": null,
        "synonymMaps": [],
        "fields": []
    },
    {
        "name": "KeywordsZhCn",
        "type": "Collection(Edm.String)",
        "facetable": true,
        "filterable": true,
        "retrievable": true,
        "searchable": true,
        "analyzer": "zh-Hans.microsoft",
        "indexAnalyzer": null,
        "searchAnalyzer": null,
        "fields": []
    }
],
"scoringProfiles": [],
"corsOptions": null,
"suggesters": [],
"analyzers": [],
"tokenizers": [],
"tokenFilters": [],
"charFilters": [],
"encryptionKey": null

}

最少的文件

{“价值”:[{“@search.action”:“mergeOrUpload”,“Id”:“1”,“KeywordsZhCn”:[“M / 6g”]
}]}

示例查询 https://{{SEARCH_SVC}}.{{DNS_SUFFIX}}/indexes/products/docs?search=M1.6&$count=true&$select=Id,KeywordsZhCn&searchMode=all&queryType=full&api-version=2020-06- 30-Preview&featuresMode=enabled&scoringStatistics=global

featuresMode 选项已启用,因此我看到了意外匹配发生的位置。

{
"@odata.context": "https://<my-search-service>.search.windows.net/indexes('products')/$metadata#docs(*)",
"@odata.count": 1,
"value": [
    {
        "@search.score": 0.25811607,
        "@search.features": {
            "KeywordsZhCn": {
                "uniqueTokenMatches": 1.0,
                "similarityScore": 0.25811607,
                "termFrequency": 1.0
            }
        },
        "Id": "1",
        "KeywordsZhCn": [
            "M / 6g"
        ]
    }
]

}

我已经在 Stack Overflow 上搜索过类似的案例,但我只能找到大约一年前我自己的一篇帖子,我在 Azure 搜索中遇到了疯狂的中文回忆问题,参考。中文查询导致出乎意料的高召回率

分析的输出用分析的输出更新我的问题。

使用 zh-Hans.microsoft 分析器分析内容“M / 6g”会产生以下标记:

"tokens": [
    {
        "token": "m",
        "startOffset": 0,
        "endOffset": 1,
        "position": 0
    },
    {
        "token": "6g",
        "startOffset": 4,
        "endOffset": 6,
        "position": 1
    }
]

查询 M1.6 产生:

    "tokens": [
    {
        "token": "m",
        "startOffset": 0,
        "endOffset": 1,
        "position": 0
    },
    {
        "token": "1.6",
        "startOffset": 1,
        "endOffset": 4,
        "position": 1
    },
    {
        "token": "nn1d6",
        "startOffset": 1,
        "endOffset": 4,
        "position": 1
    }
]

标签: azure-cognitive-searchcjkanalyzerprecision-recall

解决方案


推荐阅读