
The Suggestion Provider API enables you to add and control suggestions displayed when the user enters a search term in the Search field of the Ajax Framework Page (AFP).
The API is contained in the com.sap.portal.suggestion.providers package.
SAP NetWeaver Developer Studio is installed and started
In the portal's Framework Page Configuration for Ajax Framework Page , the Enable Quick Launch option is selected.
For more information about enabling this option, see Creating and Editing a Framework Page .
The following procedure describes how to implement and integrate a basic suggestion provider that returns a list of suggestions for a search term.
In SAP NetWeaver Developer Studio, open the Enterprise Portal perspective and create a portal application project.
For more information, see Creating a Portal Application Project .
In portalapp.xml, set a sharing reference to com.sap.portal.suggestion.providers.
In the portal application project, create a portal service, and add the startup property, setting it to true.
For more information, see Creating a Portal Service .
In the src.core folder, create a new class named SampleCategory that implements the ICategoryDescriptor interface.
public class SampleCategory implements ICategoryDescriptor
{
public String getID()
{
return "Travel";
}
public String getTitle(Locale locale)
{
return "Travel";
}
}
In the src.core folder, create a new class named SampleProvider that implements the ISuggestionProvider interface.
public class SampleProvider implements ISuggestionProvider
{
public ICategoryDescriptor getCategory()
{
return new SampleCategory();
}
public List<ISuggestion> search(String searchTerm, IUser user, Locale locale, ISuggestionFilter filter)
{
String term = searchTerm.toLowerCase(locale);
String[] words = {"photograph", "seaside", "rock", "sandstone", "sunset"};
List<ISuggestion> suggestions = new ArrayList<ISuggestion>();
for (int i = 0; i < words.length; i++)
{
SearchOption searchOption = filter.getSearchOption();
String word = words[i].toLowerCase(locale);
if ( ( (searchOption == null) || (searchOption == SearchOption.contains) && word.contains(term) ) || word.startsWith(term) )
{
Suggestion suggestion = new Suggestion();
suggestion.setTitle(word);
suggestion.setTooltip(word);
suggestion.setUrl("http://www.google.com");
suggestion.setSuggestionProvider("ProviderId");
suggestions.add(suggestion);
}
}
return suggestions;
}
}
To register the service, copy the following code to the init method of the service implementation class:
ISuggestionProviderRegistration providerService = (ISuggestionProviderRegistration) PortalRuntime.getRuntimeResources().getService(ISuggestionProviderRegistration.KEY);
ISuggestionProvider sampleProvider = new SampleProvider();
providerService.register(sampleProvider);
To unregister the service, copy the following code to the destroy method of the service implementation class:
ISuggestionProviderRegistration providerService = (ISuggestionProviderRegistration) PortalRuntime.getRuntimeResources().getService(ISuggestionProviderRegistration.KEY);
providerService.unregister(sampleProvider);
Build and deploy your application. For more information, see Deploying a Portal Application .
In the Provider Configuration screen, add and enable your search provider. For more information, see Configuring Providers .
Enter a term in the Search field in the portal, and check that the Travel category with suggestions appears below.
A client-side API that enables you to retrieve search suggestions and control their appearance