Azure搜索按不完整字词和特殊字符进行搜索不起作用 [英] Azure Search searching by not full word with special characters is not working

查看:108
本文介绍了Azure搜索按不完整字词和特殊字符进行搜索不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Azure Search .NET SDK搜索包含特殊字符的字符串.

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

我尝试转义每个特殊字符,尝试使用full query syntax并尝试使用通配符,但没有按预期工作.

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

这是方法:

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,
        };
}

我有Name字段设置为$@!Q$@!的文档.当我在查询中写它并转义感叹号(如$@\!Q$@\!)时,我得到了正确的结果.但是,当我删除最后一个!并在查询中写入*通配符时,却没有任何结果.没有任何迹象也没有结果.

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 $@\!*?

推荐答案

目前,没有内置方法可用于转义特殊字符.但是特殊字符必须转义才能用作搜索文本的一部分.您可以通过在它们前面加上反斜杠()来对其进行转义.需要转义的特殊字符包括:

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.

希望有帮助.

这篇关于Azure搜索按不完整字词和特殊字符进行搜索不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆