Implement enhancements to search results
You have an existing search service that a holiday booking app uses. You’ve seen that the relevance of search results is impacting the number of bookings you’re getting. You’ve also recently added hotels in Portugal so would like to offer Portuguese as a supported language.
In this exercise, you’ll add a scoring profile to improve the relevance of search results. Then you’ll use Azure AI Services to add Portuguese descriptions for all your hotels.
Note To complete this exercise, you will need a Microsoft Azure subscription. If you don’t already have one, you can sign up for a free trial at https://azure.com/free.
Create Azure resources
You’ll create am Azure AI Search Service and import sample hotel data.
- Sign in to the Azure portal.
- Select + Create a resource.
- Search for search, and then select Azure AI Search.
- Select Create.
- Select Create new under Resource group, name it learn-advanced-search.
- In Service name, enter advanced-search-service-12345. The name needs to be globally unique so add random numbers to the end of the name.
- Select a supported Region near you.
- Use the default values for the Pricing tier.
- Select Review + create.
- Select Create.
- Wait for the resources to be deployed, then select Go to resource.
Import sample data into the search service
Import the sample data.
-
On the Overview pane, select Import data.
- On the Import data pane, in the Data source dropdown, select Samples.
-
Select hotels-sample.
-
On the Add cognitive skills (Optional) tab, expand Attach AI Services, then select Create new AI Services resource.
Create an Azure AI Service to support translations
- In the new tab, sign in to the Azure portal.
- In Resource group, select the learn-advanced-search.
- In Region, select the same region you chose for the search service.
- In Name, enter learn-cognitive-translator-12345 or any name you prefer. The name needs to be globally unique so add random numbers to the end of the name.
- In Pricing tier, select Standard S0.
- Check By checking this box I acknowledge that I have read and understood all the terms below.
- Select Review + create.
- Select Create.
- When the resources have been created, close the tab.
Add a translation enrichment
- On the Add cognitive skills (Optional) tab, select Refresh.
- Select the new service, learn-cognitive-translator-12345.
- Expand the Add enrichments section.
- Select Translate text, change the Target Language to Portuguese, then change the Field name to Description_pt.
- Select Next: Customize target index.
Change the field to store translated text
- On the Customize target index tab, scroll to the bottom of the field list and change the Analyzer to Portuguese (Portugal) - Microsoft for the Description_pt field.
- Select Next: Create an indexer.
-
Select Submit.
The index is created, the indexer will be run, and 50 documents containing sample hotel data will be imported.
- On the Overview pane, select Indexes, then select hotels-sample-index.
- Select Search to see JSON for all of the documents in the index.
-
Search for Description_pt (you can use CTRL + F for this) in the results and note that it isn’t a Portuguese translation of the English description, but looks like this instead:
"Description_pt": "45",
The Azure portal assumes the first field in the document needs to be translated. So it’s currently using the translation skill to translate the HotelId
.
Update the skillset to translate the correct field in the document
-
At the top of the page, select the search service, **advanced-search-service-12345 Indexes** link. - Select Skillsets under Search management on the left pane, then select hotels-sample-skillset.
-
Edit the JSON document, change line 11 to:
"context": "/document/Description",
-
Change the default from language to English on line 12:
"defaultFromLanguageCode": "en",
-
Change the source field on line 18 to:
"source": "/document/Description"
- Select Save.
-
At the top of the page, select the search service, **advanced-search-service-12345 Skillsets** link. - On the Overview pane, select Indexers, then select hotels-sample-indexer.
- Select Indexer Definition (JSON).
-
Change the source field name on line 21 to:
"sourceFieldName": "/document/Description/Description_pt",
- Select Save.
- Select Reset, then Yes.
- Select Run then select Yes.
Test the updated index
-
At the top of the page, select the search service, **advanced-search-service-12345 Indexers** link. - On the Overview pane, select Indexes, then select hotels-sample-index.
- Select Search to see JSON for all of the documents in the index.
-
Search for Description_pt in the results and note that now there is a Portuguese description.
"Description_pt": "O maior resort durante todo o ano da área oferecendo mais de tudo para suas férias – pelo melhor valor! O que você pode desfrutar enquanto estiver no resort, além das praias de areia de 1,5 km do lago? Confira nossas atividades com certeza para excitar tanto os jovens quanto os jovens hóspedes do coração. Temos tudo, incluindo ser chamado de \"Propriedade do Ano\" e um \"Top Ten Resort\" pelas principais publicações.",
-
Now you’ll search for hotels that have views of lakes. We’ll start by using a simple search that returns only the
HotelName
,Description
,Category
, andTags
. In the Query string, enter this search:lake + view&$select=HotelName,Description,Category,Tags&$count=true
Look through the results and try to find the fields that matched the
lake
andview
search terms. Note this hotel and its position:{ "@search.score": 0.9433406, "HotelName": "Lady Of The Lake B & B", "Description": "Nature is Home on the beach. Save up to 30 percent. Valid Now through the end of the year. Restrictions and blackout may apply.", "Category": "Luxury", "Tags": [ "laundry service", "concierge", "view" ] },
This hotel has matched the term lake in the HotelName
field and on view in the Tags
field. You’d like to boost matches of terms in the Description
field over the hotel’s name. Ideally, this hotel should be last in the results.
Add a scoring profile to improve search results
- Select the Scoring profiles tab.
- Select + Add scoring profile.
- In Profile name, enter boost-description-categories.
-
Add the following fields and weights under Weights:
- In Field name, select Description.
- For Weight, enter 5.
- In Field name, select Category.
- For Weight, enter 3.
- In Field name, select Tags.
- For Weight, enter 2.
- Select Save.
- Select Save at the top.
Test the updated index
- Return to the Search explorer tab of the hotels-sample-index page.
-
In the Query string, enter the same search as before:
lake + view&$select=HotelName,Description,Category,Tags&$count=true
Check the search results.
{ "@search.score": 3.5707965, "HotelName": "Lady Of The Lake B & B", "Description": "Nature is Home on the beach. Save up to 30 percent. Valid Now through the end of the year. Restrictions and blackout may apply.", "Category": "Luxury", "Tags": [ "laundry service", "concierge", "view" ] }
The search score has increased, from 0.9433406 to 3.5707965. However, all the other hotels have higher calculated scores. This hotel is now last in the results.
Clean-up
Now that you’ve completed the exercise, delete all the resources you no longer need.
- In the Azure portal, select Resource Groups.
- Select the resource group you don’t need anymore, then select Delete resource group.