Newer Version Available
SuggestionOption Class
Options that narrow record and article suggestion results returned
from a call to System.Search.suggest(String, String,
Search.SuggestionOption).
Namespace
SuggestionOption Methods
The following are methods for SuggestionOption.
setFilter(knowledgeSuggestionFilter)
Set filters that narrow Salesforce Knowledge article results in a
call to System.Search.suggest(String, String,
Search.SuggestionOption).
Signature
public void setFilter(Search.KnowledegeSuggestionFilter knowledgeSuggestionFilter)
Parameters
- knowledgeSuggestionFilter
- Type: KnowledgeSuggestionFilter
- An object containing filters that narrow the search results.
Return Value
Type: void
Usage
1Search.KnowledgeSuggestionFilter filters = new Search.KnowledgeSuggestionFilter();
2filters.setLanguage('en_US');
3filters.setPublishStatus('Online');
4filters.setChannel('app');
5
6Search.SuggestionOption options = new Search.SuggestionOption();
7options.setFilter(filters);
8
9Search.SuggestionResults suggestionResults = Search.suggest('all', 'KnowledgeArticleVersion', options);
10
11for (Search.SuggestionResult searchResult : suggestionResults.getSuggestionResults()) {
12 KnowledgeArticleVersion article = (KnowledgeArticleVersion)result.getSObject();
13 System.debug(article.title);
14}setLimit(limit)
Signature
public void setLimit(Integer limit)
Parameters
- limit
- Type: Integer
- The maximum number of record or article suggestions to retrieve.
Return Value
Type: void
Usage
By default, the System.Search.suggest(String, String,
Search.SuggestionOption) method returns the 5 most relevant results. However, if
your query is broad, it could match more than 5 results. If
Search.SuggestionResults.hasMoreResults() returns true, there are more than 5 results. To retrieve them, call setLimit(Integer) to increase the number of suggestions
results.
1Search.SuggestionOption option = new Search.SuggestionOption();
2option.setLimit(10);
3Search.suggest('my query', 'mySObjectType', option);