Electromorph
Electromorph

Reputation: 11

Use different search terms for different columns

We are using Azure Search to find courses from a list. We search on three fields. We need fuzzy searches on the Coursename and Keywords, but want only to include exact matches for the course code (which has sequential numeric codes like "RB046").

Using the Search Explorer, you can do something like this with the URL:

https://xxx.search.windows.net/indexes/prospectussearchindexlive/docs?api-version=2016-09-01&search=CourseCode:"HCN_6_006" OR Coursename:"HCN_6_006~1" OR Keywords:"HCN_6_006~1"

But in the API it seems you can only have one search term applied to all specified columns. Does anyone know of a way you can do this with the API without performing two searches?

Upvotes: 0

Views: 84

Answers (1)

Arvind - MSFT
Arvind - MSFT

Reputation: 569

So as pointed out in the comments by Bruce Johnston, largely the feature set (especially with respect to search query syntax) should be identical between the REST API and the Azure search .Net SDK. The search explorer on the Azure portal, is literally a call into the REST API, so there shouldn't be any differences there.

The following search API call might translate to what you are looking for (I have included the POST version, you should be able to use GET as well if you'd like).

POST /indexes/prospectussearchindexlive/docs/search?api-version=2016-09-01  
{  
  "search": "CourseCode:HCN_6_006 OR Coursename:HCN_6_006~1 OR Keywords:HCN_6_006~1",  
  "queryType": "full",  
  "searchMode": "all"  
}  

You should take a look at the Lucene syntax for Azure search, which is here: https://learn.microsoft.com/en-us/rest/api/searchservice/lucene-query-syntax-in-azure-search that will help you write different search queries.

You can also refer to the SDK documentation here: https://learn.microsoft.com/en-us/azure/search/search-howto-dotnet-sdk which talks about how to use the .NET SDK to perform search queries. Look at the Documents.Search method for more details.

Upvotes: 1

Related Questions