Search using StartsWith in Azure Search

瘦欲@ 提交于 2019-12-08 00:13:41

问题


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 Technologies Limited
  2. Infosys BPM Limited
  3. Infor Solution
  4. Infosys Corporate Technologies
  5. Dell Computers
  6. First Infosystems

My Search Scenario is

  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

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.


回答1:


From Nate Ko's answer here:

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-practially-use-a-keywordanalyzer-in-azure-search




回答2:


Both Simple query syntax and Lucene query syntax support prefix search queries like "prefix*"and find documents that contain terms that starts with the prefix query.

So you can try something like search=info*"&searchmode=all or search=infosys tech*&searchmode=all and it should work.

If you want even more advanced regular expression like searches, you can refer to Regular expression search



来源:https://stackoverflow.com/questions/53587309/search-using-startswith-in-azure-search

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