在 Azure 搜索中使用 StartsWith 进行搜索 [英] Search using StartsWith in Azure Search

查看:25
本文介绍了在 Azure 搜索中使用 StartsWith 进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,我必须使用 Azure 搜索使用供应商名称来搜索供应商.例如下面是供应商列表.

I have scenario where I have to search the Vendors using Vendor Names using Azure Search. For Example Below is the List Of Vendors.

  1. Infosys 技术有限公司
  2. Infosys BPM 有限公司
  3. 信息解决方案
  4. Infosys 企业技术
  5. 戴尔电脑
  6. 第一信息系统

我的搜索场景是

  1. 当 Searchtext 为 Info 时,它应该返回 1,2,3,4
  2. 当 Searchtext 为 Infosys 时,它应该返回 1,2,4
  3. 当 Searchtext 为 Infosys Tech 时,它应该只返回 1 而不是 4
  1. when Searchtext is Info it should return 1,2,3,4
  2. when Searchtext is Infosys it should return 1,2,4
  3. when Searchtext is Infosys Tech it should return only 1 not 4

我还在供应商名称字段上尝试了关键字分析器,但它也没有给出我预期的结果.基本上,我希望搜索文本从供应商名称字段的开头(startswith)开始搜索,而不是单独搜索供应商名称的每个单词(Standard.Lucene Analyzer 搜索每个单词).

I also tried keyword analyzer on Vendor Name Field and it also does not give the result I expected. Basically I want the searchtext to search from start of the Vendor Name field(startswith) and not on each word(Standard.Lucene Analyzer searches on every word) of Vendor Name Separately.

您能否在这种情况下帮助我了解如何构建我的查询.

Can You Please Help me in this case on how to frame my query.

推荐答案

来自 Nate Ko 的回答 这里:

From Nate Ko's answer here:

您似乎想对整个文件发出前缀搜索查询字段值不在字段中的单个术语上.在这种情况下,您需要使用关键字分析器,以便整个字段值是标记为单个标记.例如,给定16th Ave SE"为输入,默认情况下 Azure 搜索使用标准分析器并标记化多个项的输入,如 <16th>、 和前缀搜索是根据标记化的术语发出的.如果你使用关键字分析器,而是将整个字段值标记为单个标记为 <16th ave se> 和前缀搜索 search=16th* 只会找到具有以前缀开头的字段的文档.同样,通过 regex search=/.*ave/进行后缀搜索只会找到带有字段的文档以后缀结尾.下面是相关问题堆栈溢出.

It looks like you want to issue a prefix search query on the entire field value not on the individual terms in the fields. In such case, you need to use keyword analyzer so that the entire field value is tokenized into a single token. For example, given "16th Ave SE" as input, by default Azure Search uses standard analyzer and tokenizes the input into multiple terms as <16th>, , and the prefix search is issued on the tokenized terms. If you use the keyword analyzer instead, the entire field value is tokenized as the single token as <16th ave se> and a prefix search search=16th* will only find documents with field that starts with the prefix. Likewise, the suffix search via regex search=/.*ave/ will only find docs with fields that ends with the suffix. Below are related questions on stackoverflow.

http://stackoverflow.com/questions/40056213/behavior-of-asterisk-in-azure-search-service/40137948#40137948

http://stackoverflow.com/questions/40857057/how-to-practicly-use-a-keywordanalyzer-in-azure-search

这篇关于在 Azure 搜索中使用 StartsWith 进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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