@Override
public void requestSuggestions(final Request request,
final Callback callback) {
/* Request suggestions from Oracle*/
final Response r = new Response();
final ArrayList<DisplayableItemSuggestion> suggestionList = new ArrayList<DisplayableItemSuggestion>();
// Normaize input to lower case
request.setQuery(request.getQuery().toLowerCase());
// make sure pers. suggest tree is set.
setPersonalizedSuggestTree();
// Add personalized suggestions to list
SuggestionList list = personalizedSuggestTree.getBestSuggestions(request.getQuery());
for (int i=0;i< list.length();i++){
suggestionList.add(new DisplayableItemSuggestion(list.get(i), request.getQuery(),true));
}
r.setSuggestions(suggestionList);
callback.onSuggestionsReady(request, r);
//Get suggestions
dispatcher.execute(
new RequestGlobalSearchSuggestion(request),
new AsyncCallback<RequestGlobalSearchSuggestionResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(
RequestGlobalSearchSuggestionResult result) {
// add results to local suggest tree
for (Suggestion sug : result.getResponse().getSuggestions()) {
suggestionList.add(new DisplayableItemSuggestion(sug.getDisplayString(),request.getQuery(),false));
}
r.setSuggestions(suggestionList);
callback.onSuggestionsReady(request, r);
}
});
}