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

时间:2017-05-24 12:18:54

标签: lucene azure-search

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

我有一个字段名称的跟随值。

  • 演示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开头的属性吗?
  4. 是否可以通过一次设置实现上述所有三个条件?

1 个答案:

答案 0 :(得分: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*

<强> 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. &#34;演示S&#34;将只返回Demo Site 001

  2. &#34; 001&#34;只会返回001演示网站

  3. 更多详情

    How Search works

    Custom Analyzers