Azure Search searching by not full word with special characters is not working

那年仲夏 提交于 2020-02-25 03:23:05

问题


I want to search string which contains special characters using Azure Search .NET SDK.

I've tried escaping every special character, tried using full query syntax and tried wildcards, nothing worked as expected.

Here is the method:

public virtual async Task<SearchResultDto<T>> Search(string query, SearchOptionsInput searchOptionsInput)
{
   if (!_azureOptions.IsEnabled)
   {
      return null;
   }

   var searchIndexClient = GetSearchIndexClientForGivenType();
   var searchParameters = _objectMapper.Map<SearchParameters>(searchOptionsInput);

   searchParameters.QueryType = QueryType.Full;

   var searchResult = await searchIndexClient.Documents.SearchAsync<T>(query, searchParameters);

   return new SearchResultDto<T>
        {
                Count = searchResult.Count,
                Results = searchResult.Results.Select(r => r.Document).ToList(),
                FacetResults = searchResult.Facets,
        };
}

I have document with Name field set to $@!Q$@!. When I write it in query and escape exclamation mark (like $@\!Q$@\!) I get proper result. But when I delete last ! and write * wildcard in query instead I get no results. Without any sign there's no result aswell.

Is there a way to properly write special characters so search will return results on match eg. when I write $@\!*?


回答1:


For now there is no built in method available to escape the special character. But special characters must be escaped to be used as part of the search text. You can escape them by prefixing them with backslash (). Special characters that need to be escaped include the following:

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

For example, to escape a wildcard character, use **\***.

For additional details please check the below link:

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

Please upvote the user voice request for implementing this functionality in below link, will help us prioritizing the request.

https://feedback.azure.com/forums/263029-azure-search/suggestions/32114773-provide-method-for-escaping-characters-in-the-sear

Hope it helps.



来源:https://stackoverflow.com/questions/58451056/azure-search-searching-by-not-full-word-with-special-characters-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!