2
votes

we are using azure search API but are getting no results for special characters that contain no alphanumeric characters.

We was having trouble returned any matching results for Japanese language and any special characters at all until we wrapped the string in quotes (") see the examples below (we are escaping the special characters also.

strings that did not work

var searchTerm = "嘘つきな唇で";
var searchTerm = "test@123";
var searchTerm = "?sd-^&*d$£(";

After wrapping in quotes i.e.

searchTerm = "\"" + searchTerm + "\"*"

all the above searches returned the expected matches but now we have an issue of no matches with strings with only special characters in i.e.

var searchTerm = "@@@@";
var searchTerm = "&@*(%$";

new SearchParameters
    {
       SearchFields = new List<string> {"name", "publicId"},
       Top = 50,
       SearchMode = SearchMode.Any,
       QueryType = QueryType.Simple, 
       Filter = $"status eq 1"
    }

Any help on this would be greatly appreciated

Kind regards

1
which analyzer are you using?Thiago Custodio
can you post the full search / filter parameters in your url?"Thiago Custodio
@ThiagoCustodio Ahh ok this may explain the japanese language not working as expected as we are not using any analyzer for the targeted search field although it does work wrapped in qoutes?Troublesum
I was asking you. The analyzer is specified during the indexing process. I assume you're using the default analyzer. For the second part of your question, "@" and "&:" are reserved chars. Do you really have the need to search for "@@@@" ?Thiago Custodio
"analyzer": null, "indexAnalyzer": null, "searchAnalyzer": null, is the current Index difinition setting for the searched field, the search is on user naming that had no validation when set up so yeah we have to support existing user :( the correct names are being indexed its just the search failing for themTroublesum

1 Answers

0
votes

Without escaping or using another analyzer (rather than StandardAnalyzer which is the default) I don't think you'll be able to retrieve the results as some of the samples you've provided are reserved / special chars:

Please check:

https://docs.microsoft.com/en-us/azure/search/query-lucene-syntax#escaping-special-characters

EDIT: please read about analyzers in here: https://docs.microsoft.com/en-us/azure/search/search-analyzers