Azure 搜索中多个术语或空格之间的建议(建议者) [英] Suggestions by more than one term or Space in between in Azure Search (Suggester)

查看:20
本文介绍了Azure 搜索中多个术语或空格之间的建议(建议者)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过名字、姓氏和电子邮件在下拉列表中建议用户列表我已经创建了一个索引,用 azure 控制台中的建议者标记字段,如下所示:

这仅适用于 FirstName 的查询,但不适用于 FirstName "space" LastName,当我运行此查询时,我只得到 0 个文档

示例:

姓名 John Doe

  • 约翰,我得到了所有约翰的建议
  • 约翰,我得到了所有约翰的建议
  • John D,我得到 0 个文件
  • John Doe,我得到 1 个文档

这是我的代码:

term = Uri.EscapeDataString(term);SuggestParameters sp = 新的 SuggestParameters{顶部 = 20,UseFuzzyMatching = true,SearchFields = 新列表<字符串>{ 名:姓:电子邮箱" },Select = new List{ "Id","FirstName", "LastName", "Email" },OrderBy = new List{ 名:姓:电子邮箱" },};var docs = await _indexClient.Documents.SuggestAsync(term, "sg", sp);

  • 我可以按诸如 FirstName 之类的术语拆分查询吗?第二个是姓氏?
  • 我需要以不同的方式转义这个词吗?
  • 是否可以使用通配符来实现类似 SQL 中的 Like 表达式 之类的行为?

任何帮助将不胜感激

解决方案

回答您的问题:

  • **我可以按如下方式拆分查询:一个是名字,第二个是姓氏?**

为了说明,我们不以下面的例子为例:

POST/indexes/Flights/docs/search?api-version=2019-05-06{"search": "头等舱,宽敞的座位* +"阿联酋航空"","searchFields": "描述,标题","searchMode": "任何","filter": "price ge 60 and price lt 300","orderby": "geo.distance(location, geography'POINT(-449.476235 11.212349)')",查询类型":完整"}

对于此请求,搜索引擎执行以下操作:

  • 过滤掉价格至少为 60 美元且低于 300 美元的文档.
  • 执行查询.在此示例中,搜索查询由短语和术语组成:First Class, Spacious Seats* +"Emirates""(用户通常不输入标点符号,但在示例中包含它可以让我们解释分析器如何处理它).对于此查询,搜索引擎会扫描 searchFields 中指定的描述和标题字段,以查找包含Emirates"的文档,以及First Class"一词或以前缀Spacious Seats"开头的词.searchMode 参数用于匹配任何词条(默认)或所有词条,用于不明确要求词条 (+) 的情况.

  • 按与给定地理位置的接近程度对生成的航班集进行排序,然后返回到调用应用程序.

我相信,通过这种方式,您将能够进行基于 **OR** 的搜索.

  • 我需要以不同的方式转义这个词吗?

同上

是否可以使用通配符来实现类似 SQL 中 Like 表达式的行为?

您可以参考链接进行通配符搜索.>

参考:

https://littlekendra.com/2016/10/25/wildcard-vs-regular-expressions-lucene-query-in-azure-search/

希望有帮助.

I need to suggest a list of users in a dropdown by FirstName, LastName, and Email I have created an index marking the fields with the suggester in the azure console as follows:

This only works for a query by the FirstName but not for FirstName "space" LastName, when I run this query I just get 0 documents

Example:

Name John Doe

  • John, I get suggestions for all Johns
  • John , I get suggestions for all Johns
  • John D, I get 0 documents
  • John Doe, I get 1 document

This is my code:

term = Uri.EscapeDataString(term);
SuggestParameters sp = new SuggestParameters
{
    Top = 20,
    UseFuzzyMatching = true,
    SearchFields = new List<string> { "FirstName", "LastName","Email" },
    Select = new List<string> { "Id","FirstName", "LastName", "Email" },
    OrderBy = new List<string> { "FirstName", "LastName", "Email" },
};
var docs = await _indexClient.Documents.SuggestAsync(term, "sg", sp);

  • Can I split the query by terms like one to be the FirstName and the second one to be the LastName?
  • Do I need to scape the term in a different way?
  • Is there any wildcard I can use to have a similar behavior like a Like expresion in SQL?

Any help will be appreciated

解决方案

To Answer your question:

  • **Can I split the query by terms like one to be the FirstName and the second one to be the LastName?**

For Illustration, let't take below example:

POST /indexes/Flights/docs/search?api-version=2019-05-06
{
    "search": "First Class, Spacious Seats* +"Emirates"",
    "searchFields": "description, title",
    "searchMode": "any",
    "filter": "price ge 60 and price lt 300",
    "orderby": "geo.distance(location, geography'POINT(-449.476235 11.212349)')", 
    "queryType": "full" 
}

For this request, the search engine does the following:

  • Filters out documents where the price is at least $60 and less than $300.
  • Executes the query. In this example, the search query consists of phrases and terms: "First Class, Spacious Seats* +"Emirates"" (users typically don't enter punctuation, but including it in the example allows us to explain how analyzers handle it). For this query, the search engine scans the description and title fields specified in searchFields for documents that contain "Emirates", and additionally on the term "First Class", or on terms that start with the prefix "Spacious Seats". The searchMode parameter is used to match on any term (default) or all of them, for cases where a term is not explicitly required (+).

  • Orders the resulting set of flights by proximity to a given geography location, and then returned to the calling application.

I believe , by this way you will be able to do **OR** based search.

  • Do I need to scape the term in a different way?

Same as above

Is there any wildcard I can use to have a similar behavior like a Like expresion in SQL?

You can refer this link for wildcard search.

Reference:

https://littlekendra.com/2016/10/25/wildcard-vs-regular-expressions-lucene-query-in-azure-search/

Hope it helps.

这篇关于Azure 搜索中多个术语或空格之间的建议(建议者)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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