SearchAPIClient Apex Class
SearchAPIClient Apex Class
Coveo for Salesforce 3.38 (August 2019)
You can use this Apex classes to call the SearchAPI.
You should also consult the:
Methods
querySuggestResponse
Represents the structure of a response from the QuerySuggestion API. It contains the following attributes:
-
expression
: the expression to complete the query. -
score
: the score associated to the query suggestion. -
executableConfidence
: the confidence ratio given by Coveo Machine Learning (Coveo ML).
querySuggest
Calls the API to request query suggestions (see querySuggestPost). You can use the following params
:
-
body
: the body of the querySuggest request. It should include at least:locale
,q
, andsearchHub
. -
authorization
: the content of the Authorization header to send (for example,Bearer TOKEN
).
String token = CoveoV2.Globals.generateSearchToken();
List<CoveoV2.SearchApiClient.QuerySuggestResponse> suggestions = CoveoV2.SearchApiClient.querySuggest(
new Map<String,Object>{
'locale' => 'en',
'q' => '',
'searchHub' => 'hub'
},
'Bearer ' + token);
System.debug(suggestions);
executeQuery
Executes a query to the organization currently linked to the package or any uri.
String token = CoveoV2.Globals.generateSearchToken();
CoveoV2.SearchApiResponse response = CoveoV2.SearchApiClient.executeQuery(
new Map<String,Object>{
'q' => 'my query text'
},
'Bearer ' + token);
System.debug(response);