我为索引和Azure搜索中的字段设置了默认的Analyzer。
我有一个字段名称的跟随值。
我正在尝试获取以下匹配值。我的示例查询是
$count=true&queryType=full&searchFields=name&searchMode=any&$select=name,id&$skip=0&$top=10&search=name:/"Demo(.*)/
我可以得到所有结果
Demo S
获取,即Demo Site 001
。我应该对查询做出什么改变?或者我应该对分析仪做出哪些改变?001
,001和空格,我该如何修改查询?001
开头的属性吗?是否可以通过一次设置实现上述所有三个条件?
答案 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" ]
}
]
采用任何这些方法
&#34;演示S&#34;将只返回Demo Site 001
&#34; 001&#34;只会返回001演示网站
更多详情: