1

I'm trying to find all records which contain & symbol, which is reserved. I'm using search, not $filter.

According to documentation, it can not be escaped with \%, and should be escaped as HTML url part to %26.

Trying SDK and Search explorer to find any options on how to search, but with no succeed:

  1. &
  2. *&*
  3. *%26*
  4. %26
  5. \%26

UPD

Document example:

{
    "test": "Hello & World"

Search query: 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

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
dr11
  • 5,166
  • 11
  • 35
  • 77
  • Did you try all those options in both SDK and Search explorer? I am posting an answer below, but for the SDK option 1 should've just worked, unless you change the defaults. Can you post a code example in case that didn't work – Arvind - MSFT Nov 21 '19 at 20:47
  • Also, just to make sure - it should be escaped to `%26` (as stated in your list) and not `%24` (as stated in the sentence above it) – Arvind - MSFT Nov 21 '19 at 20:49
  • I want to fix it least with Search Explorer. Updating the post – dr11 Nov 22 '19 at 16:35
  • Are there any other reasons why the document might be filtered out? Could you try using the keyword analyzer (instead of the default analyzer) https://learn.microsoft.com/en-us/azure/search/index-add-custom-analyzers#AnalyzerTable and see if that helps? – Arvind - MSFT Nov 24 '19 at 21:08
  • this approach did not help. actually, I don't think it's ok to have entire field as a token in our case. we need a full text scored search on this field. also, we are using search and filter capabilities – dr11 Nov 25 '19 at 16:16

2 Answers2

2

You likely can't find & because it's being removed at indexing and query time, since it's considered to be punctuation by the default analyzer. 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.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
1

In the search explorer field on the Azure portal try the query &search=%26(as shown below)

enter image description here

In the SDK, only if you have set the UseHttpGetForQueries parameter to true, you would need to think of URL encoding the '&' character. By default, this parameter is set to false in which case you don't need to encode it.

More documentation about escaping/encoding here

Arvind - MSFT
  • 561
  • 2
  • 6