Suggesters

The suggestions feature in Azure Search is a type-ahead query capability, providing a list of potential search terms in response to partial string inputs entered into a search box. You've probably noticed query suggestions when using commercial web search engines: typing ".NET" in Bing produces a list of terms for ".NET 4.5", ".NET Framework 3.5", and so forth. Using the service REST API, implementing suggestions in a custom Azure Search application requires the following:

  • Enable suggestions by adding a suggester construction in your index, giving the name, search mode, and a list of fields for which type-ahead is invoked. For example, if you specify "cityName" as a source field, typing a partial search string of "Sea" will result in "Seattle", "Seaside", and "Seatac" (all three are actual city names) offered up as query suggestions to the user.

  • Invoke suggestions by calling the Suggestions (Azure Search Service REST API) in your application code. Typically partial search strings are sent to the service while the user is typing a search query, and this API returns a set of suggested phrases.

    This article explains how to configure a Suggester. You should also review the Suggestions (Azure Search Service REST API) for details on how a Suggester is used.

Usage

Suggesters are created in the index and work best when used to suggest specific documents rather than loose terms or phrases. The best candidate fields are titles, names, and other relatively short phrases that can identify an item. Less effective are repetitive fields, such as categories and tags, or very long fields such as descriptions or comments fields.

As part of the index definition, you can add a single suggester to the suggesters collection. Properties that define a suggester include the following:

Property Description
name The name of the suggester. You use the name of the suggester when calling the Suggestions (Azure Search Service REST API).
searchMode The strategy used to search for candidate phrases. The only mode currently supported is analyzingInfixMatching, which performs flexible matching of phrases at the beginning or in the middle of sentences.
sourceFields A list of one or more fields that are the source of the content for suggestions. Only fields of type Edm.String and Collection(Edm.String) may be sources for suggestions. Only fields that don't have a custom language analyzer set can be used.

Suggester example

A suggester is part of the index. Only one suggester can exist in the suggesters collection in the current version, alongside the fields collection and scoringProfiles.

{  
  "name": "hotels",  
  "fields": [  
     . . .   
   ],  
  "suggesters": [  
    {  
    "name": "sg",  
    "searchMode": "analyzingInfixMatching",  
    "sourceFields": ["hotelName", "category"]  
    }  
  ],  
  "scoringProfiles": [  
     . . .   
  ]  
}  

See Also

Create Index (Azure Search Service REST API)
Update Index (Azure Search Service REST API)
Suggestions (Azure Search Service REST API)
Index operations (Azure Search Service REST API)
Azure Search Service REST
Azure Search .NET SDK