对Azure认知搜索文档中的嵌套数组执行like/contains/match操作

vdzxcuhz  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(90)

我在索引文件中有以下数据

[
  {
    "HotelId": "1",
    "HotelName": "Secret Point Motel",
    "Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
    "Tags": [
      "Free wifi",
      "on-site **park**ing",
      "indoor pool",
      "continental breakfast"
    ],
    "Address": {
      "StreetAddress": "677 5th Ave",
      "City": "New York",
      "StateProvince": "NY"
    }
  },
  {
    "HotelId": "2",
    "HotelName": "SBS Greenotel",
    "Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
    "Tags": [
      "Free wifi",
      "Paid wifi",
      "on-site **park**ing",
      "podium **park**ing",
      "indoor pool",
      "continental breakfast"
    ],
    "Address": {
      "StreetAddress": "677 5th Ave",
      "City": "New York",
      "StateProvince": "NY"
    }
  }
]

字符串
并且想搜索标签中包含或匹配搜索短语 “公园”(以上数据中 * 突出显示 *)的酒店
我尝试了search.ismatch函数,但lambda表达式不支持它。
任何帮助形成odata查询将不胜感激。

g52tjvyc

g52tjvyc1#

一个可能的解决方案是在索引模式中包含analyzer,以实现关键字的部分匹配。
我创建了一个索引,下面的schema:

index_schema = {
    "name": "hotels8",
    "fields": [
        {"name": "HotelId", "type": "Edm.String", "key": True, "searchable": False},
        {"name": "HotelName", "type": "Edm.String", "searchable": True},
        {"name": "Description", "type": "Edm.String", "searchable": True},
        {
            "name": "Tags",
            "type": "Collection(Edm.String)",
            "searchable": True,
            "analyzer": "partial_match_analyzer",
        },
        {
            "name": "Address",
            "type": "Edm.ComplexType",
            "fields": [
                {"name": "StreetAddress", "type": "Edm.String", "searchable": True},
                {"name": "City", "type": "Edm.String", "searchable": True},
                {"name": "StateProvince", "type": "Edm.String", "searchable": True},
            ],
        },
    ],
    "analyzers": [
        {
            "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
            "name": "partial_match_analyzer",
            "tokenizer": "standard_v2",
            "tokenFilters": ["lowercase", "my_edgeNGram"],
        }
    ],
    "tokenFilters": [
        {
            "@odata.type": "#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
            "name": "my_edgeNGram",
            "minGram": 4,
            "maxGram": 25,
            "side": "front",
        }
    ],
}

字符串
并上传了以下数据:

"value": [
        {
            "@search.action": "upload",
            "HotelId": "1",
            "HotelName": "Secret Point Motel",
            "Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
            "Tags": ["Free wifi", "on-site parking", "indoor pool", "continental breakfast"],
            "Address": {
                "StreetAddress": "677 5th Ave",
                "City": "New York",
                "StateProvince": "NY"
            },
        },
        {
            "@search.action": "upload",
            "HotelId": "2",
            "HotelName": "SBS Greenotel",
            "Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
            "Tags": ["Free wifi", "Paid wifi", "on-site parking", "podium parking", "indoor pool", "continental breakfast"],
            "Address": {
                "StreetAddress": "677 5th Ave",
                "City": "New York",
                "StateProvince": "NY"
            },
        },
        {
            "@search.action": "upload",
            "HotelId": "3",
            "HotelName": "SBS Greenotel2",
            "Description": "Ideally located on the main commercial artery of the city in the heart of New York.",
            "Tags": ["Free wifi", "Paid wifi", "indoor pool", "continental breakfast"],
            "Address": {
                "StreetAddress": "677 5th Ave",
                "City": "New York",
                "StateProvince": "NY"
            },
        },
    ]


使用标签字段分析器,我可以通过搜索查询获得结果:“park

**注意:**请根据您的需求修改schema。
有关详细信息,请参阅此文档。
你也可以用类似的问题检查这个thread

相关问题