JsSearch Visualforce component
JsSearch Visualforce component
The Coveo for Salesforce package comes with a Visualforce component that imports all the required dependencies for the Coveo JavaScript Search Framework. It also preconfigures the search endpoint with search tokens.
Usage
Reference it in your Visualforce page as you would for any other Apex component, using the namespace prefix of the Coveo package.
<CoveoV2:JsSearch />
Resources included with this component
This component includes the following resources in the header of your page:
-
The JavaScript Search Framework dependencies (for example,
CoveoJsSearch.Dependencies.js
).This can be either the minified or debug version, depending on the options set on the Apex component.
-
The JavaScript Search Framework scripts themselves (for example,
CoveoJsSearch.js
) containing the code for all of the components.This can be either the minified or debug version, depending on the options set on the Apex component.
-
The default result templates included in the product.
-
Language detection relies on the current user language set in Salesforce, not on the user browser language, but you can change the language, if needed (see Change the language of your search interface).
-
The CSS for the different components.
JavaScript code included and executed with this component
-
The Search Endpoint is created with the right URL and options. The Search Endpoint also includes the search token that the current user needs to perform secure query in Coveo.
The search token is generated server-side, as described in the Use search token authentication page. The process is done in Apex code, which is included in the package when the page is first loaded.
The token is included with each query to correctly identify the Coveo user.
-
Since search tokens expire after a certain delay for security reasons, a user that would have the same search page open for a long time would be unable to perform queries. As such, this component includes the needed JavaScript code to renew this token on demand when it expires.
Options
These options are set directly on the Apex component.
stylesheet
The default value is CoveoFullSearch.css
.
This option provides a way to change the stylesheet used for the Search Page.
<CoveoV2:JsSearch stylesheet="<MY_STYLESHEET>" />
Where you can replace <MY_STYLESHEET>
by the stylesheet you want to use for your Search Page.
filter
This option is empty by default.
This adds a query expression (or filter) inside the search token generated for the current page. This filter is executed on every query.
Since it’s included in the cryptographically signed JWT token, client code can’t tamper with this.
<CoveoV2:JsSearch filter="<MY_FILTER>" />
Where you can replace <MY_FILTER>
with the filter you want to add to the search token generated for the current page (for example, @sfkbid
).
searchHub
This option is empty by default.
The name of the search hub to be sent to Coveo Usage Analytics (Coveo UA).
Since it’s included in the cryptographically signed JWT token, client code can’t tamper with this.
<CoveoV2:JsSearch searchHub="<MY_SEARCH_HUB>" />
Where you replace <MY_SEARCH_HUB>
by the name of the search hub when reporting events to Coveo Usage Analytics (Coveo UA).
Note
If you read the documentation about the Analytics component, you will realize that it’s also possible to set the
|
Important
Having a conflicting search hub in the body of the request and the search token results in the analytics event being rejected. The response from the service looks like this:
|
catalog
Note
The |
This option is empty by default.
This specifies the catalog ID that the JsSearch Visualforce component must use.
<CoveoV2:JsSearch catalog="<MY_CATALOG_ID>" />
Where you can replace <MY_CATALOG_ID>
with the ID of the catalog that you want your JsSearch Visualforce component to use.
debug
The default value is false
.
Setting this value to true
causes the debug version of the JavaScript libraries to be used.
The debug
versions aren’t minified.
In a production environment, we strongly recommend that you use the minified version for faster download times of the resources as well as marginally faster execution time.
For debugging purpose, you can enable this option to read the source code more easily.
<CoveoV2:JsSearch debug="false" />
userGroups
This is the list of user groups to append to the current user, separated by semicolons. Each of these user groups is added in the search token.
Since it’s included in the cryptographically signed JWT token, client-side code can’t tamper with this.
These user groups are used in Coveo UA as additional reporting dimensions.
<CoveoV2:JsSearch usersGroups="<GROUP1>;<GROUP2>;<GROUP3>" />
Where you can replace <GROUP1>
, <GROUP2>
, and <GROUP3>
by respectively the name of the user groups to append to the current user.
You can add as many user groups as you want.
additionalUserIdentities
List of user identities to append to the current user, separated by semicolons. Each of these identities are added in the search token and allow a given user to add other identities that this user should have.
<CoveoV2:JsSearch additionalUserIdentities="john@doe.com;jane@doe.com;name=doe\jane,provider=Active Directory,type=User" />
If you need to specify other security providers, you can specify them with param=value
separated by commas where:
-
name
is the identity name. -
provider
is the security provider name. The default value isEmail Security Provider
. -
type
is user or group. The default value isUser
.
Since it’s included in the cryptographically signed JWT token, client code can’t tamper with this.
This could allow users not logged into Salesforce to be able to query as if they were another anonymous user and allow them to see public items.
This could also be used to map a Salesforce user to an Active Directory user, or any other system.
anonymousUser
Specifies the identity to use for non-logged in users.
<CoveoV2:JsSearch anonymousUser="<IDENTITY>" />
Where you replace <IDENTITY>
with the identity you want to use for non-logged in users (for example, anonymous@user.com
).
customVersion
This option is empty by default.
This specifies the list of components that the JsSearch Visualforce component must use.
<CoveoV2:JsSearch customVersion="<COMPONENT1>;<COMPONENT2>;<COMPONENT3>" />
Where you can replace <COMPONENT1>
, <COMPONENT2>
, and <COMPONENT3>
by respectively the name of the components that the JsSearch Visualforce component must use.
You can add as many components as you want.
searchContext
<CoveoV2:JsSearch searchContext="{!context}" />
This lets you create an additional context inside your search page (see Send Apex context to a JavaScript search interface).