I have scenario where I have to search the Vendors using Vendor Names using Azure Search. For Example Below is the List Of Vendors.
- Infosys Technologies Limited
- Infosys BPM Limited
- Infor Solution
- Infosys Corporate Technologies
- Dell Computers
- First Infosystems
My Search Scenario is
- when Searchtext is Info it should return 1,2,3,4
- when Searchtext is Infosys it should return 1,2,4
- 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.
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/40857057/how-to-practially-use-a-keywordanalyzer-in-azure-search
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