如何在 Azure 搜索中匹配以下查询

How to match following queries in Azure Search

我为我的索引和 Azure 搜索中的字段设置了默认分析器。

我有以下字段值 - 名称。

我正在尝试获取以下 的匹配值。我的示例查询是

$count=true&queryType=full&searchFields=name&searchMode=any&$select=name,id&$skip=0&$top=10&search=name:/"Demo(.*)/

我可以得到所有的结果

  1. 为了得到只得到Demo S的查询工作,即Demo Site 001。我应该对查询进行哪些更改?或者我应该对分析器进行哪些更改?
  2. 如果我想要使用 001、001 和 space 的查询,我该如何修改查询?
  3. 最后有什么方法可以告诉搜索我只需要以 001 开头的属性?

是否可以通过一次设置实现以上三个条件?

有 2 种可能的方法可以实现此目的。

一个。带有 CharMap 过滤器的自定义分析器

1. For index phase, you can use a Custom Analyzer with a character filter to map whitespaces to underscores/emptystring.
   eg:If you map whitespaces to emptystring, your data will be stored as:
    Demo Site 001 ---> DemoSite001
    001 Demo Site ---> 001DemoSite
     "charFilters":[
    {
       "name":"map_dash",
       "@odata.type":"#Microsoft.Azure.Search.MappingCharFilter",
       "mappings":[" =>"]
    }


   In query phase, 
      Step 1. Parse the query and substitute whitespace with the same identifier, as used in the index phase.
          So , search query "Demo S" translates to  ---> "DemoS"
      Step 2. Do a wildcard  search for the new query string
          search = DemoS*

乙。带有 EdgeNGramToken 过滤器的自定义分析器

Use a custom analyzer , with a EdgeNGram TokenFilter to index your documents.
eg:
"tokenFilters": [
{
  "name": "edgeNGramFilter",
  "@odata.type": "#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
  "minGram": 2,
  "maxGram": 20
}
],
"analyzers": [
  {
    "name": "prefixAnalyzer",
    "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
    "tokenizer": "keyword",
    "tokenFilters": [ "lowercase", "edgeNGramFilter" ]
  }
]

使用这些方法中的任何一种

  1. "Demo S" 将 return 仅演示站点 001

  2. “001”只会 return 001 演示站点

更多详情

How Search works

Custom Analyzers