user2981411
user2981411

Reputation: 950

Azure Search Suggester

The suggester in Azure Search has only 1 SearchMode and that is it will match on any word within the field. Although this might be appropriate for many applications, it also is not for many others. Is there any way we can configure the suggester so that a match occurs only when the beginning of the field is a match? Many thanks for your assistance.

Upvotes: 3

Views: 1280

Answers (2)

Yahnoosh
Yahnoosh

Reputation: 1972

Consider creating a custom analyzer that at index time generates prefixes of words from your documents:

{
   "name":"names",
   "fields": [
      { "name":"id", "type":"Edm.String", "key":true, "searchable":false },         
      { "name":"partialName", "type":"Edm.String", "searchable":true, "searchAnalyzer":"standard", "indexAnalyzer":"prefixAnalyzer" }
   ],
   "analyzers": [
      {
        "name":"prefixAnalyzer",
        "@odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
        "tokenizer":"standard",
        "tokenFilters":[ "lowercase", "my_edgeNGram" ]
      }
   ],
   "tokenFilters": [
      {
        "name":"my_edgeNGram",
        "@odata.type":"#Microsoft.Azure.Search.EdgeNGramTokenFilter",
        "minGram":2,
        "maxGram":20
      }
   ]
}

Notice the partialName field uses the standard analyzer for search and the custom (prefixAnalyzer) analyzer for indexing. You can now issue regular Search requests with prefixes of words as query terms.

You can learn more about the EdgeNGramTokenFilter from our documentation page about Analysis in Azure Search.

Let me know if this helps.

Upvotes: 3

Bruce Johnston
Bruce Johnston

Reputation: 8634

Currently only infix matching is supported in suggestions.

Upvotes: 0

Related Questions