【问题标题】:How to match following queries in Azure Search如何在 Azure 搜索中匹配以下查询
【发布时间】:2017-05-24 12:18:53
【问题描述】:

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

我有以下字段值 - 名称。

  • 演示001
  • 演示站点 001
  • 001 演示站点

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

$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 和空格的查询,我该如何修改查询?
  3. 最后有什么方法可以告诉搜索我只需要以001 开头的属性吗?

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

【问题讨论】:

  • 公平地说,您需要将名称按原样编入索引,而不需要分词,然后找到与前缀匹配的名称吗?案例2呢?您希望退回哪些文件?以下文章介绍了 Azure 搜索中搜索引擎的默认行为并说明了如何对其进行自定义:docs.microsoft.com/en-us/azure/search/…
  • 是的,您的第一句话应该有效。但是我尝试将字段的分析器更改为 Keyword 。尽管该字段确实索引为字符串。我无法使用前缀查询。还有'001'我希望得到最后一个选项

标签: lucene azure-cognitive-search


【解决方案1】:

有两种可能的方法来实现这一点。

A.带有 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*

B.带有 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”将仅返回 Demo Site 001

  2. “001”将仅返回 001 演示站点

更多详情:

How Search works

Custom Analyzers

【讨论】:

  • 谢谢,我也在考虑使用 Azure 搜索建议器来做这件事
猜你喜欢
  • 2018-02-17
  • 1970-01-01
  • 2020-11-09
  • 2018-05-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多