-
Notifications
You must be signed in to change notification settings - Fork 1
Stage 6: Create and Configure Azure Search
Create and configure the Azure Search Service using the Microsoft link.
-
Follow all the instructions provided in the link. Choose 'Free' tier instead of 'Standard' for this POC.
-
Now create an Indexer to load data into the search service index. Follow instructions from link.
-
In Step 1, point 2 from the above link, ensure to select "SQL Database" as the Data Source instead of "Samples".
-
Rest of the configurations can be followed. Connect to the Database that was created for this POC in Stage 4.
-
In Step 3 from the above link, you can use the IndexSchema.png image to configure the index.
- Once defined, many field attributes cannot be changed via Portal and API's.
- Copy of the Index Definition JSON file is also added in the source repo for reference.
-
In Step 4 create the Indexer and configure a 'Once' schedule.
-
Navigate to the 'Search Explorer' and try the default search with the pre-filled input in the Request URL. This should now return all the values from the index.
-
For reference on queryType 'full' which processes Lucene query syntax, check the link.
Configure appsettings.json key values for AzureSearchSettings.
- Navigate to the 'Setting -> Keys' and copy paste the Primary Admin Key to the appsettings.json 'queryApiKey'.
- Copy and paste the Search Service Name from 'Settings -> Properties -> Name' to the appsettings.json searchServiceName key.
- Copy and paste the Index name from 'Overview -> Indexes -> Name' to the appsettings.json 'indexName' key.
- Below code uses the searchServiceName, indexName and queryApiKey from the appsettings.json file to create an instance of the search index client.
//Create a search index client object to interact with Azure Search Service.
indexClient = new SearchIndexClient(searchServiceName, indexName,new SearchCredentials(queryApiKey));
-
The below code uses a Switch case construct to update the filter parameter based on the LUIS entity passed as a parameter to this function.
-
Entity creation in LUIS and its corresponding Search query should be well thought of. For complex queries, helper and mapper classes need to be added.
-
Using Cognitive Services Skillsets in Search index pipeline could be better alternative to reduce developing queries based on LUIS intents.
private async Task<DocumentSearchResult<dynamic>> AzureSearchQueryRequest(List<dynamic> luisEntities)
{
----skipped----
Switch (entity.type.ToString())
{
case "BikeMike.Color":
filter += filter.Length > 0 ? ($" AND Color eq '{entity.resolution.values[0].ToString()}'") : ($"Color eq '{entity.resolution.values[0].ToString()}'");
break;
case "BikeMike.BikeTypes":
----skipped----
}
The Search Parameters and query (*) is then passed on to the index client for async execution to return a list of dynamic objects.
searchParameters = new SearchParameters()
{
Filter = filter,
Select = new[] { "BikeName", "BaseRate", "Color" }
};
searchResults = (await indexClient.Documents.SearchAsync<dynamic>("*", searchParameters));