Skip to main content

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

alt_text

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:

  1. In the top navigation, click Settings, and then click Secrets. The Manage Secrets page appears.
  2. Click Add Secret. The Create Secret wizard appears.
  3. For Secret Code, enter an identifier for the Secret: algolia-api-key.
  4. For Name, enter a friendly name for the Secret: Algolia API Key.
  5. Optionally, enter a Description for the Secret.
  6. For Secret Value, enter your Algolia API key.
  7. Click Submit.

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:

  1. In the top navigation, click Manage Experiences, and then click Components. The Manage Components page appears.
  2. Click Add Component. The Create Component wizard appears.
  3. For Component Code, enter an identifier for the Component: configuration-values.
  4. For Component Name, enter a friendly name for the Component: Configuration Values.
  5. Optionally, enter a Component Description for the Component.
  6. For Component Type, select Conscia - Metadata.
  7. Click Submit.

To create an Experience Rule to configure the Configuration Values (configuration-values) Metadata Orchestration Component, in the DX Engine UI:

  1. In the top navigation, click Manage Experiences, and then click Experiences. The Manage Omnichannel Experiences page appears.
  2. Expand All Components, select the Configuration Values Component, and then click Add Experience Rule. The Create Component Rule wizard appears.
  3. For Rule ID, enter default-configuration-values.
  4. For Rule Name, enter Default Configuration Values.
  5. For Priority, enter 100. In the future, give any additional Experience Rules that you create to override default configuration values a lower Priority.
  6. Select the Is Default checkbox.
  7. From the dropdown at the top right, select Experience.
  8. Under Instructions, click Add Another Item.
  9. For Key, enter algoliaIndexName.
  10. For Value, enter the identifier of the Algolia index.
  11. 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:

  1. In the top navigation, click Settings, and then click Connections. The Manage Connections page appears.
  2. Click Add Connection. The Create Connection wizard appears.
  3. For Connection Code, enter algolia-connection.
  4. For Connection Name, enter Algolia Connection.
  5. Optionally, enter a Connection Description.
  6. For Connector, select Algolia.
  7. Under API Key, set Get value from to Secret and select the Algolia API Key (algolia-api-key) Secret.
  8. For Application ID, enter your Algolia application ID.
  9. 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:

  1. Click Manage Experiences, and then click Components. The Manage Components page appears.
  2. Click Add Component. The Create Component wizard appears.
  3. For Component Code, enter algolia-search.
  4. For Component Name, enter Algolia Search.
  5. Optionally, enter a Component Description.
  6. Select the No Rules checkbox. Experience Rules do not apply to this Component.
  7. For Component Type, select Algolia - Search.
  8. Click Submit.

To configure the Algolia Search (algolia-search) Orchestration Component, in the Manage Components page:

  1. Next to the Algolia Search (algolia-search) Orchestration Component, click the Edit icon. The Edit Component wizard appears.
  2. For Connection, select the Algolia Connection (algolia-connection) Connection.
  3. Under Index Name, set Get value from to JS Expression and enter the following JavaScript expression:
`${componentResponse('configuration-values').algoliaIndexName[0]}`
  1. Under Type, set Get value from to Literal and enter default.
  2. Under Query, set Get value from to JS Expression and enter the following JavaScript expression:
`${contextField('searchTerm')}`
  1. 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.

  1. Under Strategy, set Get value from to Literal and enter none.
  2. 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.

  1. 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
}

References