【发布时间】:2020-05-08 03:29:39
【问题描述】:
我正在尝试查找所有包含& 符号的记录,该符号是保留的。我使用的是search,而不是$filter。
根据文档,它不能用\% 转义,应该作为HTML url 部分转义到%26。
尝试使用 SDK 和搜索资源管理器查找有关如何搜索的任何选项,但没有成功:
&*&**%26*%26\%26
UPD
文档示例:
{
"test": "Hello & World"
搜索查询:search=%26&searchFields=test&$select=test
UPD 2
public class MyType
{
[System.ComponentModel.DataAnnotations.Key]
[IsFilterable]
public string Id { get; set; }
[IsSearchable, IsSortable]
public string Test { get; set; }
}
class Program
{
private static SearchServiceClient CreateSearchServiceClient()
{
string searchServiceName = "XXXXXX";
string adminApiKey = "XXXXXXX";
var serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));
return serviceClient;
}
static void Main(string[] args)
{
var client = CreateSearchServiceClient();
var def = new Microsoft.Azure.Search.Models.Index
{
Name = "temp-test-reserved1",
Fields = FieldBuilder.BuildForType<MyType>()
};
client.Indexes.Create(def);
var c = client.Indexes.GetClient("temp-test-reserved1");
var actions = new IndexAction<MyType>[]
{
IndexAction.Upload(new MyType{ Id = "1", Test = "Hello & World" }),
IndexAction.Upload(new MyType{ Id = "2", Test = "& test start" }),
IndexAction.Upload(new MyType{ Id = "3", Test = "test end &" })
};
c.Documents.Index(IndexBatch.New(actions));
}
}
search=%26&searchFields=Test&$select=Test
【问题讨论】:
-
您是否在 SDK 和搜索资源管理器中尝试了所有这些选项?我在下面发布了一个答案,但对于 SDK 选项 1 应该刚刚工作,除非您更改默认值。如果不起作用,您可以发布一个代码示例吗
-
另外,只是为了确保 - 它应该转义到
%26(如您的列表中所述)而不是%24(如上面的句子中所述) -
我想用搜索资源管理器修复它。更新帖子
-
还有其他原因导致文档被过滤掉吗?您能否尝试使用关键字分析器(而不是默认分析器)docs.microsoft.com/en-us/azure/search/… 看看是否有帮助?
-
这种方法没有帮助。实际上,在我们的案例中,我不认为将整个字段作为标记是可以的。我们需要在该字段上进行全文评分搜索。此外,我们正在使用搜索和过滤功能
标签: azure-cognitive-search azure-search-.net-sdk