2

Has anyone here implemented autocomplete feature of azure search with Sitecore?

I see documentation on how to add a suggester while creating an index in azure, but Sitecore documentation (https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/search_and_indexing/using_solr_autosuggest) only mentions solr suggester configuration, and I don't see corresponding dlls for azure on nuget (Sitecore.ContentSearch.SolrProvider.dll, Sitecore.ContentSearch.SolrNetExtension.dll)

Any ideas?

2

Azure does not support solr suggester for sitecore, but as a workaround you can create a separate index where you store only text information that you want to use for suggestions (to get suggestions fast) that you will be use like a suggester dictionary.

Example of suggesting by field "Title":

public class TitleSearchResultItem
{
    [IndexField("title")]
    public string Title { get; set; }
}

Suggest method:

public IEnumerable<string> Suggest(string term, int count = 5)
{
            char[] delimiters = { ' ', ',', ';', '.', ':', '-' };

            var words = term.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            var predicate = PredicateBuilder.True<TitleSearchResultItem>();
            predicate = words.Aggregate(predicate, (current, t) =>
            {
                return current.And(x => x.Title.StartsWith(t).Boost(10) || x.Title.Contains(t).Boost(5));
            });

            var contextIndex = _contextRepository.GetSearchIndexContext("custom_suggester_index");
            using (var context = contextIndex.CreateSearchContext())
            {
                var results = context.GetQueryable<TitleSearchResultItem>()
                    .Where(predicate)
                    .Take(count)
                    .Select(x => new { x.Title });

                return results.Select(x => x.Title).ToList();
            }
}
1

Following list for features that exist in Azure that are not currently supported by your Sitecore provider:

  • Geospatial data types
  • Indexers
  • Suggestions
  • Highlighters

Source: Sitecore Azure Search overview

  • Note that SXA adds support for geospatial and suggestions. – Mark Gibbons May 16 '19 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.