Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use AzureSearch with wildcard

I want to search for a field that has the name "14009-00080300", and I want to get a hit when searching only on a part of that, for example "14009-000803".

Using this code I dont get any hits:

   {
 "search": "\"14009-000803\"*",
 "count":true,
 "top":10
}

Is there a way to use azure search like SQL uses its wildcard search? (select * from table where col like '%abc%' ?

like image 589
Flubber Avatar asked Dec 01 '17 10:12

Flubber


2 Answers

You can get your desired result by performing a full query with Lucene syntax (as noted by Sumanth BM). The trick is to do a regex search. Modify your query params like so:

{
 "queryType": "full",
 "search": "/.*searchterm.*/",
 "count":true,
 "top":10
}

Replace 'searchterm' with what you are looking for and azure search should return all matches from your index searchable columns.

See Doc section: MS Docs on Lucene regular expression search

like image 181
Indregaard Avatar answered Sep 30 '22 12:09

Indregaard


You can use generally recognized syntax for multiple () or single (?) character wildcard searches. Note the Lucene query parser supports the use of these symbols with a single term, and not a phrase. For example to find documents containing the words with the prefix "note", such as "notebook" or "notepad", specify "note".

Note You cannot use a * or ? symbol as the first character of a search. No text analysis is performed on wildcard search queries. At query time, wildcard query terms are compared against analyzed terms in the search index and expanded.

SearchMode parameter considerations The impact of searchMode on queries, as described in Simple query syntax in Azure Search, applies equally to the Lucene query syntax. Namely, searchMode in conjunction with NOT operators can result in query outcomes that might seem unusual if you aren't clear on the implications of how you set the parameter. If you retain the default, searchMode=any, and use a NOT operator, the operation is computed as an OR action, such that "New York" NOT "Seattle" returns all cities that are not Seattle.

https://docs.microsoft.com/en-us/rest/api/searchservice/simple-query-syntax-in-azure-search

Reference: https://docs.microsoft.com/en-us/rest/api/searchservice/lucene-query-syntax-in-azure-search#bkmk_wildcard

like image 37
SumanthMarigowda-MSFT Avatar answered Sep 30 '22 11:09

SumanthMarigowda-MSFT