Generate a custom search token for the Community Hosted Search Page component
Generate a custom search token for the Community Hosted Search Page component
To override the default search token for your Community Hosted Search Page configuration, you must generate a custom search token to authenticate queries on the Coveo Community Hosted Search Page component. Custom search tokens are typically used to add additional parameters to the search token. See Use search token authentication for details.
To generate a custom search token
-
In the new Apex class, enter the following template:
global with sharing class <MY_APEX_CLASS> implements CoveoV2.SearchTokenGeneratorInterface { public String generateSearchToken(Map<String, Object> params) { Map<String, Object> searchTokenOptions = new Map<String, Object>(); // Make sure to include this part when generating your custom search token. if (params.containsKey('searchHub')) { String searchHub = (String) params.get('searchHub'); searchTokenOptions.put('searchHub', searchHub); } // Example of how to add additional user identities to the search token. List<CoveoV2.UserIdentity> additionalUserIdentities = new List<CoveoV2.UserIdentity>{ new CoveoV2.UserIdentity('johndoe@coveo.com'), new CoveoV2.UserIdentity('john@doe.com', 'Email Security Provider'), new CoveoV2.UserIdentity('john@doe.com', 'Email Security Provider', 'User') }; searchTokenOptions.put('additionalUserIdentities', additionalUserIdentities); String token = CoveoV2.Globals.generateSearchToken(searchTokenOptions); return token; } }
Where you replace
<MY_APEX_CLASS>
with the name you chose for your new Apex class.The Apex class must be
global
and it must implementCoveoV2.SearchTokenGeneratorInterface
. Otherwise, it won’t appear as an option in the Token Generator picklist on the Coveo Community Hosted Search Page component. -
(Optional) Override the default search token parameters. See the
generateSearchToken
reference documentation for details.The value of the
searchHub
parameter received when thegenerateSearchToken
function is called will match the name of your hosted search page configuration. This value must not be changed and it must be added to the search token options. -
Save the Apex class.
What’s Next?
Once you have an Apex class that implements CoveoV2.SearchTokenGeneratorInterface
, it will appear as an option in the Token Generator picklist on the Coveo Community Hosted Search Page component.
You can now select your new Apex class to override the default search token for your Community Hosted Search Page configuration.