Azure 搜索 - 查询 & 字符

Azure Search - querying for ampersand character

我正在尝试查找所有包含 & 符号的记录,该符号已保留。我使用的是 search,而不是 $filter

根据文档,它不能用 \% 转义,应该作为 HTML url 部分转义到 %26.

正在尝试使用 SDK 和搜索浏览器查找有关如何搜索的任何选项,但没有成功:

  1. &
  2. *&*
  3. *%26*
  4. %26
  5. \%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

在 Azure 门户的搜索浏览器字段中尝试查询 &search=%26(如下所示)

在SDK中,只有当您将UseHttpGetForQueries参数设置为true时,您才需要考虑URL编码'&'字符。默认情况下,此参数设置为 false,在这种情况下您不需要对其进行编码。

关于 escaping/encoding here

的更多文档

您可能找不到 &,因为它在索引和查询时被删除,因为它被默认分析器视为标点符号。 This article has more details on lexical analysis in Azure Cognitive Search. If you need to preserve ampersands while still tokenizing text on whitespace boundaries, you'll need to create a custom analyzer.