如何在天蓝色搜索中搜索带有中间破折号的术语?
How to search a term with a middle dash in azure search?
我正在学习使用 azure 搜索,但我没有找到一种方法来在 ItemId 字段中搜索带有中间破折号的术语,我不关心要搜索的术语是在开头还是在中间。
我的索引中有这些字段和数据
+-----+--------------------+-------------+
| Cat | ItemId | Description |
+-----+--------------------+-------------+
| 100 | 400800-1100103U | desc item 1 |
| 100 | 400800-11001066 | desc item 2 |
| 100 | 400800-11001068 | desc item 3 |
| 101 | 400800-110010F6 | desc item 4 |
+-----+--------------------+-------------+
这是我的索引字段配置:
+-------------+-------------+-----------+-----------+-----------+------------+
| Field Name | Retrievable | Filerable | Sortable | Facetable | Searchable |
+-------------+-------------+-----------+-----------+-----------+------------+
| Cat | OK | OK | OK | OK | X |
| ItemId | OK | OK | OK | OK | OK |
| Description | OK | | | | |
+-------------+-------------+-----------+-----------+-----------+------------+
这是我对字段 ItemId 的自定义分析器,即使有中间破折号也只生成一个标记。
{
"@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
"name": "keyword_lowercase",
"tokenizer": "keyword_v2",
"tokenFilters": [
"lowercase"
],
"charFilters": []
}
如果我使用此查询进行搜索:$select=RowKey&search=400800-1100*
我得到这些结果:
- 400800-1100103U
- 400800-11001066
- 400800-11001068
- 400800-110010F6
但是如果我尝试使用这样的中间词进行搜索:$select=RowKey&search=RowKey:(00800-1100*)~
我得到 0 个结果。
那么如何在 ItemId 中搜索带有中间破折号的字词,而不关心要搜索的字词是在开头还是在中间?
我认为 this post answers your question by using regular expression search but has some considerations. Alternatively you can consider using fuzzy search or use the Edge N-gram tokenizer with a reverse token filter 取决于您的具体情况。
我删除了分析器并在请求正文中使用此代码通过 POST 更改 GET。
{
"queryType": "full",
"search": "/.*00-11.*/",
"searchFields": "ItemId",
"select": "ItemId",
"count": true,
"top": 10
}
使用带有 Lucene 语法分析器和正则表达式的完整查询 属性,搜索按预期工作。
请注意,如果您尝试在 Azure 的查询搜索浏览器中使用此正则表达式,return 不会有任何结果。我认为这是因为搜索浏览器使用了 GET 请求。
感谢 Corom - MSFT 的回答。有用。我只想回答得更清楚
我正在学习使用 azure 搜索,但我没有找到一种方法来在 ItemId 字段中搜索带有中间破折号的术语,我不关心要搜索的术语是在开头还是在中间。
我的索引中有这些字段和数据
+-----+--------------------+-------------+
| Cat | ItemId | Description |
+-----+--------------------+-------------+
| 100 | 400800-1100103U | desc item 1 |
| 100 | 400800-11001066 | desc item 2 |
| 100 | 400800-11001068 | desc item 3 |
| 101 | 400800-110010F6 | desc item 4 |
+-----+--------------------+-------------+
这是我的索引字段配置:
+-------------+-------------+-----------+-----------+-----------+------------+
| Field Name | Retrievable | Filerable | Sortable | Facetable | Searchable |
+-------------+-------------+-----------+-----------+-----------+------------+
| Cat | OK | OK | OK | OK | X |
| ItemId | OK | OK | OK | OK | OK |
| Description | OK | | | | |
+-------------+-------------+-----------+-----------+-----------+------------+
这是我对字段 ItemId 的自定义分析器,即使有中间破折号也只生成一个标记。
{
"@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
"name": "keyword_lowercase",
"tokenizer": "keyword_v2",
"tokenFilters": [
"lowercase"
],
"charFilters": []
}
如果我使用此查询进行搜索:$select=RowKey&search=400800-1100*
我得到这些结果:
- 400800-1100103U
- 400800-11001066
- 400800-11001068
- 400800-110010F6
但是如果我尝试使用这样的中间词进行搜索:$select=RowKey&search=RowKey:(00800-1100*)~
我得到 0 个结果。
那么如何在 ItemId 中搜索带有中间破折号的字词,而不关心要搜索的字词是在开头还是在中间?
我认为 this post answers your question by using regular expression search but has some considerations. Alternatively you can consider using fuzzy search or use the Edge N-gram tokenizer with a reverse token filter 取决于您的具体情况。
我删除了分析器并在请求正文中使用此代码通过 POST 更改 GET。
{
"queryType": "full",
"search": "/.*00-11.*/",
"searchFields": "ItemId",
"select": "ItemId",
"count": true,
"top": 10
}
使用带有 Lucene 语法分析器和正则表达式的完整查询 属性,搜索按预期工作。
请注意,如果您尝试在 Azure 的查询搜索浏览器中使用此正则表达式,return 不会有任何结果。我认为这是因为搜索浏览器使用了 GET 请求。
感谢 Corom - MSFT 的回答。有用。我只想回答得更清楚