Working on Typeahead

Today, I am working on typeahead with Azure Search.

I am reading, https://docs.microsoft.com/en-us/azure/search/search-autocomplete-tutorial

Before you proceed, you need to make sure you have your suggester fieldset.  Per index, you can have only one suggester field.

On your page use this javascript

This code above uses the jQuery UI Autocomplete library. (https://jqueryui.com/autocomplete/ , see the API here http://api.jqueryui.com/autocomplete/) you can go to https://code.jquery.com/ and find CDN version to simply copy paste to the page.

Now, let’s look at HomeController.cs (or any controller that you set to be called from the javascript)  and related classes to return the suggestions.

/home/suggest?highlihts=false&fuzzy=false needs to return Jason format result.

I actually keep my Azure Search management services in different classes, where I have a method to return a list of suggestions in strings like below.

Then, I have home controller calling this method and return Json as below.

This is it, it works beautifully.

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.