Search with Algolia
You can implement a DX Engine orchestration flow based on this recipe that returns results from an Algolia search index based on a search term supplied through the Context. This recipe uses the Algolia Search Orchestration Component type which connects directly to Algolia’s JavaScript SDK to search across one or more indices and/or facets with a single method call.
Mapping Out DX Engine Elements
This recipe involves the following components:
- The Algolia API Key (
algolia-api-key
) Secret to store the Algolia API key. - The Configuration Values (
configuration-values
) Metadata Orchestration Component to manage configuration values. - The Default Configuration Values (
default-configuration-values
) Experience Rule to define default configuration values. - The Algolia Connection (
algolia-connection
) Connection to manage the connection to Algolia. - The Algolia Search (
algolia-search
) Orchestration Component to implement the search. - The
searchTerm
Context value to pass the search term to the orchestration flow. - The
maxResults
Context value to specify the maximum number of search results to return.
DX Engine Configuration Details
The topics in this section explain how to implement the elements involved in this recipe.
The Algolia API Key (algolia-api-key
) Secret
To create the Algolia API Key (algolia-api-key
) Secret used to store the Algolia API Key, in the DX Engine UI:
- Navigate to the Secrets page (Settings --> Secrets).
- Click the + Add Secret button.
- Enter the following and click Submit:
Field | Value |
---|---|
Secret Code | algolia-api-key |
Secret Name | Algolia API Key |
Secret Value | Enter your Algolia API key. |
The Configuration Values (configuration-values
) Metadata Orchestration Component
To create the Configuration Values (configuration-values
) Metadata Orchestration Component used to store configuration values, in the DX Engine UI:
- In the top navigation, click Manage Experiences, and then click Components. The Manage Components page appears.
- Click Add Component. The Create Component wizard appears.
- For Component Code, enter an identifier for the Component:
configuration-values
. - For Component Name, enter a friendly name for the Component:
Configuration Values
. - Optionally, enter a Component Description for the Component.
- For Component Type, select Conscia - Metadata.
- Click Submit.
To create an Experience Rule to configure the Configuration Values (configuration-values
) Metadata Orchestration Component, in the DX Engine UI:
- In the top navigation, click Manage Experiences, and then click Experiences. The Manage Omnichannel Experiences page appears.
- Expand All Components, select the Configuration Values Component, and then click Add Experience Rule. The Create Component Rule wizard appears.
- For Rule ID, enter
default-configuration-values
. - For Rule Name, enter
Default Configuration Values
. - For Priority, enter
100
. In the future, give any additional Experience Rules that you create to override default configuration values a lower Priority. - Select the Is Default checkbox.
- From the dropdown at the top right, select Experience.
- Under Instructions, click Add Another Item.
- For Key, enter
algoliaIndexName
. - For Value, enter the identifier of the Algolia index.
- Click Submit.
The Algolia Connection (algolia-connection
) Connection
To create the Algolia Connection (algolia-connection
) Connection to manage the connection to Algolia, in the DX Engine UI:
- In the top navigation, click Settings, and then click Connections. The Manage Connections page appears.
- Click Add Connection. The Create Connection wizard appears.
- For Connection Code, enter
algolia-connection
. - For Connection Name, enter
Algolia Connection
. - Optionally, enter a Connection Description.
- For Connector, select Algolia.
- Under API Key, set Get value from to Secret and select the Algolia API Key (
algolia-api-key
) Secret. - For Application ID, enter your Algolia application ID.
- Click Submit.
The Algolia Search (algolia-search
) Orchestration Component
To create the Algolia Search (algolia-search
) Orchestration Component that invokes Algolia search, in the DX Engine UI:
- Click Manage Experiences, and then click Components. The Manage Components page appears.
- Click Add Component. The Create Component wizard appears.
- For Component Code, enter
algolia-search
. - For Component Name, enter
Algolia Search
. - Optionally, enter a Component Description.
- Select the No Rules checkbox. Experience Rules do not apply to this Component.
- For Component Type, select Algolia - Search.
- Click Submit.
To configure the Algolia Search (algolia-search
) Orchestration Component, in the Manage Components page:
- Next to the Algolia Search (
algolia-search
) Orchestration Component, click the Edit icon. The Edit Component wizard appears. - For Connection, select the Algolia Connection (
algolia-connection
) Connection. - Under Index Name, set Get value from to JS Expression and enter the following JavaScript expression:
`${componentResponse('configuration-values').algoliaIndexName[0]}`
- Under Type, set Get value from to Literal and enter
default
. - Under Query, set Get value from to JS Expression and enter the following JavaScript expression:
`${contextField('searchTerm')}`
- Under params, set Get value from to JS Expression and enter the following JavaScript expression:
_.identity({'hitsPerPage': contextField('maxResults')})
This expression uses the Lodash identity()
function to pass the value of the maxResults
key from Context to Algolia under the hitsPerPage
key.
- Under Strategy, set Get value from to Literal and enter
none
. - Under requestOptions, set Get value from to JS Expression and enter the following JavaScript expression:
_.identity({})
This expression uses the Lodash identity()
function to pass an empty value to Algolia under the requestOptions
key.
- Click Submit.
Testing
To test, use the DX Engine Debugger to invoke the Algolia Search (algolia-search
) Orchestration Component with Context such as the following:
{
"searchTerm": "{replace-with-your-search-term}",
"maxResults": 100
}