
The Suggestion API enables you to retrieve and control suggestions displayed when the user enters a search term. The API has the following methods:
getSuggestions (term, callback, suggestionFilter)
Returns portal navigation suggestions for a search term, and passes this data to the specified callback function
Parameters
|
Parameter |
Description |
|
term |
A search term |
|
callback |
A callback function to which an array of Suggestion object s for the search term is passed |
|
suggestionFilter |
A SuggestionFilter object for the search term |
All methods of this API should be called with the following prefix:
EPCM.getSAPTop().LSAPI.getSuggestionPlugin().
Example
// Create a suggestion filter
var filter = new (EPCM.getSAPTop()).SuggestionFilter();
// Set the number of suggestions for each category to 22
filter.setNumSuggestions(22);
// Set the search option to "contains"
filter.setSearchOption( EPCM.getSAPTop().SearchOption.contains );
// Select the suggestion categories to "Documents" and "Navigation"
filter.setCategories("Documents;Navigation");
// Get suggestions from the default provider according to the search term "art" and filter
EPCM.getSAPTop().LSAPI.suggestionPlugin.getSuggestions("art", suggestionCallback, filter);
// Callback function to which suggestions are passed
function suggestionCallback( searchTerm, suggestions )
{
if( !suggestions ) // no suggestions passed
{
return;
}
// Loop through the suggestions array and retrieves their data.
for(var i = 0 ; i < suggestions.length ; i++)
{
var suggestion = suggestions[i];
var url = suggestion.getURL();
var title = suggestion.getTitle();
var tooltip = suggestion.getTooltip();
var navMode = suggestion.getNavMode();
var categoryTitle = suggestion.getGroupTitle();
var iconURL = suggestion.getIconURL();
var providerId = suggestion.getProviderId();
}
}
Implementing a Custom Suggestion Provider
How to use the server-side Suggestion Provider to extend the portal mechanism of search suggestions.