如何使用 Lucene 语法使用 Azure AI 搜索过滤器进行空格搜索

问题描述 投票:0回答:1

我正在使用 Azure 搜索和 azure.search.documents.SearchOptions

我有这个可以用

SearchOptions searchOptions = new SearchOptions()
    .setFilter("search.ismatch('.*golden.*', 'description', 'full', 'all')");

上面给出了描述中是否在任何地方包含“金色”一词的结果。

但是如果我尝试让它搜索多个单词,那么它就不起作用。我将使用“golden rod”这个词作为示例,我想在其中找到任何地方包含字符串“golden rod”的任何描述。

我尝试过的:

  • search.ismatch('.*golden rod.*', 'description', 'full', 'all')
  • search.ismatch('.*golden?rod.*', 'description', 'full', 'all')
  • search.ismatch('.*golden.?rod.*', 'description', 'full', 'all')
  • search.ismatch('.*golden\\ rod.*', 'description', 'full', 'all')
azure lucene azure-cognitive-search
1个回答
0
投票

这是我创建的示例索引


{
  "@odata.context": "https://searchservicename.search.windows.net/indexes('index')/$metadata#docs(*)",
  "value": [
    {
      "@search.score": 1,
      "HotelId": "3",
      "Description": "Motel 6 Golden"
    },
    {
      "@search.score": 1,
      "HotelId": "2",
      "Description": "Rodeway Inn"
    },
    {
      "@search.score": 1,
      "HotelId": "1",
      "Description": "Golden Rod Motel"
    }
  ]
}

enter image description here

// Define sample documents
        var documents = new List<SearchDocument>
        {
            new SearchDocument
            {
                { "HotelId", "1" },
                { "Description", "Golden Rod Motel" }
            },
            new SearchDocument
            {
                { "HotelId", "2" },
                { "Description", "Rodeway Inn" }
            },
            new SearchDocument
            {
                { "HotelId", "3" },
                { "Description", "Motel 6 Golden" }
            },
            // Add more sample documents as needed
        };

要使用 Azure 认知搜索筛选器和 Lucene 语法搜索包含空格的多个单词,可以使用以下方法:

   '\"golden rod\"', 'Description', 'full', 'all'

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.