用于中缀搜索的Azure搜索N元语法标记程序配置

vxf3dgd4  于 2023-01-27  发布在  其他
关注(0)|答案(1)|浏览(108)

我目前正在使用azure搜索,为了实现中缀搜索,如在**'redwine'中搜索'win'**,应该会在搜索结果中找到redwine。在azure中,我的N元语法标记器配置如下

"analyzers": [
    {
      "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
      "name": "myCustomAnalyzer",
      "tokenizer": "nGram",
      "tokenFilters": [
        "my_NGram"
      ],
      "charFilters": []
    }
  ]
"tokenFilters": [
    {
      "@odata.type": "#Microsoft.Azure.Search.NGramTokenFilterV2",
      "name": "my_NGram",
      "minGram": 2,
      "maxGram": 3
    }
  ]

现在,根据我的理解,上述配置应返回给我的红葡萄酒令牌应为Re, Red, ed, Wi, Win, in, ine, ne,但相反,当我检查使用Azure分析端点生成的令牌时,生成的令牌低于,即只有最小克2个字符长度。此配置中可能缺少什么。

{
    "@odata.context": "https://trialsearchresource.search.windows.net/$metadata#Microsoft.Azure.Search.V2021_04_30_Preview.AnalyzeResult",
    "tokens": [
        {
            "token": "re",
            "startOffset": 0,
            "endOffset": 2,
            "position": 1
        },
        {
            "token": "ed",
            "startOffset": 1,
            "endOffset": 3,
            "position": 3
        },
        {
            "token": "dw",
            "startOffset": 2,
            "endOffset": 4,
            "position": 5
        },
        {
            "token": "wi",
            "startOffset": 3,
            "endOffset": 5,
            "position": 7
        },
        {
            "token": "in",
            "startOffset": 4,
            "endOffset": 6,
            "position": 9
        },
        {
            "token": "ne",
            "startOffset": 5,
            "endOffset": 7,
            "position": 11
        }
    ]
}

P.S我正在使用Azure搜索.Net核心SDK

hc2pp10m

hc2pp10m1#

您使用的是tokenFilters,并且您尝试根据上面的预期结果定义的是tokenizer,它允许最小克数为2,最大克数为3。以下定义应有助于您实现所需的目标:

"analyzers": [
    {
      "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
      "name": "myCustomAnalyzer",
      "tokenizer": "myTokenizer",
      "charFilters": ["myCharMapping"]
    }
  ],
  "tokenizers": [
    {
      "name":"myTokenizer",
      "@odata.type":"#Microsoft.Azure.Search.NGramTokenizer",
      "minGram": 2,
      "maxGram": 3      
   }
  ],
  "charFilters": [
    {
      "@odata.type": "#Microsoft.Azure.Search.MappingCharFilter",
      "name": "myCharMapping",
      "mappings": [
        "\\u0020=>"
      ]
    }
  ]

注意,我添加了一个charFilter来删除空格,因为如果没有它,标记器也会将白色Map为gram的一部分,所以对于“red wine”,将有gram:“d“、“w”、“艾德“、“wi”等等。

相关问题