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.
Asked
Active
Viewed 1,194 times
3
-
I've added an item on our User Voice site for your request: https://feedback.azure.com/forums/263029-azure-search/suggestions/11112582-support-prefix-matching-for-suggestions Please vote for it to help us prioritize. Thanks! – Bruce Johnston Dec 16 '15 at 18:30
-
It should be noted that this is not only a "A Nice to Have Feature" - without it, the usabliity of Azure Search is seriously undermined in many applications - including ours ! – user2981411 Dec 16 '15 at 18:52
2 Answers
3
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.

Yahnoosh
- 1,932
- 1
- 11
- 13
-
Many thanks. Interesting solution but I imagine this would bloat the index substantially. We thought instead using the Documents.Search (as opposed to Suggest) and using a custom analyzer as you demonstrated in the other post using a keyword tokenizer. Is there any performance difference between Documents.Search and Documents.Suggest? Would this solution be faster than the one we are thinking of using a keyword tokenizer and having postwildcard queries like q*. Thanks for you r help. – user2981411 Dec 18 '15 at 01:51
-
1You can imagine that in order to build the Suggest API we have to do similar tricks on the backend. Suggest and Search are different only because your documents and queries are processed differently in terms of lexical analysis, besides that there is no difference in performance. Generally the approach with EdgeNGramTokenFilter will be much faster than wildcard queries because we'll be looking for exact query term -> indexed term matches rather than scanning the inverted index for terms that partially match a query term with a wildcard. Does this answer your question? – Yahnoosh Dec 18 '15 at 18:51
-
@Yahnoosh can you take a look on this one? https://stackoverflow.com/questions/57684546/suggester-by-more-than-one-term-in-azure-search thanks – pedrommuller Aug 28 '19 at 03:16