Add custom context to the Console Hosted Search Page component
Add custom context to the Console Hosted Search Page component
In this article
To add custom context to the Coveo Console Hosted Search Page component, you must create a custom Apex class that implements CoveoV2.HostedCustomContextInterface
as described in this article.
To add custom context
-
Create an Apex class that implements
CoveoV2.HostedCustomContextInterface
as follows:global class MyCustomContext implements CoveoV2.HostedCustomContextInterface { public Map<String, Object> getCustomContext(Map<String, Object> data) { // Returns the map of custom context values that will be added to each query. return new Map<String, Object>{ 'key1' => 'value1',
'listOfValues' => new List<String>{'listValue1', 'listValue2'}
}; } }
key1
is the context key/value pair to add to each query.listOfValues
is the array of context values to add to each query.Exampleglobal class MyCustomContext implements CoveoV2.HostedCustomContextInterface { public Map<String, Object> getCustomContext(Map<String, Object> data) { return new Map<String, Object>{ 'country' => 'Canada', 'role' => 'Admin', 'department' => 'IT', 'interests' => new List<String>{'encryption', 'cloud', 'security'} }; } }
-
Save the Apex class.
What’s next?
Once you’ve created an Apex class that implements CoveoV2.HostedCustomContextInterface
, you can select it from the Custom Context Provider picklist in the Coveo Console Hosted Search Page component to augment queries with the additional context returned by your custom Apex class.