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.

  1. Sign in to the Azure portal.
  2. Select + Create a resource.
  3. Search for search, and then select Azure AI Search.
  4. Select Create.
  5. Select Create new under Resource group, name it learn-advanced-search.
  6. 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.
  7. Select a supported Region near you.
  8. Use the default values for the Pricing tier.
  9. Select Review + create.
  10. Select Create.
  11. Wait for the resources to be deployed, then select Go to resource.

Import sample data into the search service

Import the sample data.

  1. On the Overview pane, select Import data.

    A screenshot showing the import data menu.

  2. On the Import data pane, in the Data source dropdown, select Samples.
  3. Select hotels-sample.

  4. On the Add cognitive skills (Optional) tab, expand Attach AI Services, then select Create new AI Services resource.

    A screenshot showing selecting, adding, Azure AI Services.

Create an Azure AI Service to support translations

  1. In the new tab, sign in to the Azure portal.
  2. In Resource group, select the learn-advanced-search.
  3. In Region, select the same region you chose for the search service.
  4. 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.
  5. In Pricing tier, select Standard S0.
  6. Check By checking this box I acknowledge that I have read and understood all the terms below.
  7. Select Review + create.
  8. Select Create.
  9. When the resources have been created, close the tab.

Add a translation enrichment

  1. On the Add cognitive skills (Optional) tab, select Refresh.
  2. Select the new service, learn-cognitive-translator-12345.
  3. Expand the Add enrichments section. A screenshot showing adding Portuguese translation.
  4. Select Translate text, change the Target Language to Portuguese, then change the Field name to Description_pt.
  5. Select Next: Customize target index.

Change the field to store translated text

  1. 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.
  2. Select Next: Create an indexer.
  3. Select Submit.

    The index is created, the indexer will be run, and 50 documents containing sample hotel data will be imported.

  4. On the Overview pane, select Indexes, then select hotels-sample-index.
  5. Select Search to see JSON for all of the documents in the index.
  6. 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

  1. At the top of the page, select the search service, **advanced-search-service-12345 Indexes** link.
  2. Select Skillsets under Search management on the left pane, then select hotels-sample-skillset.
  3. Edit the JSON document, change line 11 to:

     "context": "/document/Description",
    
  4. Change the default from language to English on line 12:

     "defaultFromLanguageCode": "en",
    
  5. Change the source field on line 18 to:

     "source": "/document/Description"
    
  6. Select Save.
  7. At the top of the page, select the search service, **advanced-search-service-12345 Skillsets** link.
  8. On the Overview pane, select Indexers, then select hotels-sample-indexer.
  9. Select Indexer Definition (JSON).
  10. Change the source field name on line 21 to:

     "sourceFieldName": "/document/Description/Description_pt",
    
  11. Select Save.
  12. Select Reset, then Yes.
  13. Select Run then select Yes.

Test the updated index

  1. At the top of the page, select the search service, **advanced-search-service-12345 Indexers** link.
  2. On the Overview pane, select Indexes, then select hotels-sample-index.
  3. Select Search to see JSON for all of the documents in the index.
  4. 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.",
    
  5. 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, and Tags. 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 and view 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

  1. Select the Scoring profiles tab.
  2. Select + Add scoring profile.
  3. In Profile name, enter boost-description-categories.
  4. Add the following fields and weights under Weights:

    A screenshot of weights being added to a scoring profile.

  5. In Field name, select Description.
  6. For Weight, enter 5.
  7. In Field name, select Category.
  8. For Weight, enter 3.
  9. In Field name, select Tags.
  10. For Weight, enter 2.
  11. Select Save.
  12. Select Save at the top.

Test the updated index

  1. Return to the Search explorer tab of the hotels-sample-index page.
  2. 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.

Delete exercise resources

Now that you’ve completed the exercise, delete all the resources you no longer need.

  1. In the Azure portal, select Resource Groups.
  2. Select the resource group you don’t need anymore, then select Delete resource group.