2

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

Troublesum
  • 285
  • 1
  • 3
  • 14
  • which analyzer are you using? – Thiago Custodio Feb 11 '20 at 14:44
  • can you post the full search / filter parameters in your url?" – Thiago Custodio Feb 11 '20 at 14:52
  • @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 Feb 11 '20 at 15:42
  • 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 Feb 11 '20 at 15:45
  • "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 them – Troublesum Feb 11 '20 at 15:50

1 Answers1

0

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://learn.microsoft.com/en-us/azure/search/query-lucene-syntax#escaping-special-characters

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

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • We are not using Lucene search we are using simple search and we are escaping the special characters above as quoted here https://learn.microsoft.com/en-us/azure/search/query-lucene-syntax#escaping-special-characters . also @ is not a special character its a Reserved characters that need to be encoded and have tried %40 but does not work either. Some experimenting is needed for the analyser for sure as you suggested. I will report back with findings. Thanks for your time :) – Troublesum Feb 11 '20 at 16:19
  • 1
    by default, @ symbol is considered a stop word. You need to escape / use a different analyzer that does not consider it as stop word and also, don't remove special chars – Thiago Custodio Feb 11 '20 at 16:23
  • this is the default: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.search.models.standardanalyzer?view=azure-dotnet – Thiago Custodio Feb 11 '20 at 16:25