AutoComplete setup and ready to go
Taking things further
Watch our autocomplete video tutorial or read more below;
We'll be running through the different auto complete options available to you and then we'll demonstrate how to further customize the suggestions that are displayed to your end users.
In this tutorial, we'll be using the JavaScript method of usage but all the following features are also available with our alternative Control based usage if you prefer. Please see the documentation for details.
AutoComplete namespace
Show the number of suggestions
Let's say we want to change the number of auto-complete suggestions shown as you type a query - simply add the following function to your page;You can see that the maximum number of suggestions has changed to ‘3’ in our example.
Deactivate search on select
Another option available to us is to deactivate ‘search on select’ so that the user has to click the search button after choosing an autocomplete suggestion;Display number of search results
We can also show the estimated number of results for each autocomplete suggestion;Changing the source of suggestions
or
The algorithm uses an attenuating window to keep new queries important and prevent the popular-search list becoming too large over time.
Your Own Suggestions
To achieve this, simply create a new index directory that contains the source you want to use for autocomplete suggestions. This could be a word list, a database of product names or anything else.
Once you've created your new index directory for autocomplete suggestions, you just need to set the path to your new index directory;
Your Own Text Controls
To use your own search button to initiate search, you just need to set the button's ID to sew_searchButton and add this onclick event;
Your Own Logic
So, on the page with the SearchBox, specify a function like this;
this will be automatically called by the autocomplete engine when suggestions are generated, allowing for modification of the suggestion list or items in the list.
In this example we’re going to turn each suggestion in to a wildcard, and also add a bonus suggestion, with 10 predicted results;
//how to iterate the generated suggestions
for (var i = 0; i < suggestions.length; i++) {
var suggestionText = suggestions[i][0];
//# of results, will be -1 if AutoCompleteQueryShowNumberOfResults==false
var suggestionNumberOfResults = suggestions[i][1];
//modify the text?
suggestions[i][0] = suggestions[i][0] + "*"; //turn each suggestion into a wildcard
}
//add a bonus suggestion, with '10' predicted results
suggestions[suggestions.length] = ["bonus", 10];
}