Build search interfaces

This is for:

Developer
Important

Atomic for Commerce components are in open beta and remain under active development.

Atomic for Commerce hasn’t yet gone through a formal accessibility review. If you have accessibility needs, contact your customer success manager and we’ll work with you to address them.

All commerce search interfaces in Atomic use the atomic-commerce-search-box component, which is the main building block that provides search box functionality. To work properly, it must be placed inside a atomic-commerce-interface with the type attribute set to search (the default value).

Prerequisite

Make sure that you understand how to build commerce search pages.

Code Sample

Following is a minimal example of a search interface built with Atomic for Commerce. This uses getSampleCommerceEngineConfiguration from @coveo/headless/commerce for its configuration. This won’t work in a production environment.

For a detailed breakdown of how to configure your search interface, refer to the Coveo Headless documentation for CommerceEngineConfiguration.

You can find a complete example of a search interface in Storybook.

<html>
  <head>
    <title>Example Search Page</title>
      <script
          type="module"
          src="https://static.cloud.coveo.com/atomic/v3/atomic.esm.js"> 1
      </script>
      <link
          rel="stylesheet"
          href="https://static.cloud.coveo.com/atomic/v3/themes/coveo.css"/> 2
    <script type="module">
      (async () => {
        const {
          getSampleCommerceEngineConfiguration
        } = await import('http://static.cloud.coveo.com/headless/v3/commerce/headless.esm.js'); 3

        const siteRoot = 'https://www.example.com/';
        const siteConfig = {
          'Example Search Page': {
            href: 'index.html',
            label: 'Example Home',
            resourceUrl: `${siteRoot}/search` 4
          },
        };

        const {context, ...restOfConfiguration} = getSampleCommerceEngineConfiguration(); 5
        const configuration = {
            context: {
              ...context,
              view: {
                url: siteConfig[document.title]?.resourceUrl,
              },
            },
            ...restOfConfiguration,
        };

        await customElements.whenDefined('atomic-commerce-interface');
        const commerceInterface = document.querySelector('atomic-commerce-interface');
        await commerceInterface.initialize(configuration); 6
        commerceInterface.executeFirstRequest();
      })();
    </script>
  </head>
  <body>
    <atomic-commerce-interface>
      <atomic-commerce-layout>
        <atomic-layout-section section="search">
          <atomic-commerce-search-box></atomic-commerce-search-box> 7
        </atomic-layout-section>
        <atomic-layout-section section="main">
          <atomic-layout-section section="products">
            <atomic-commerce-product-list
              display="grid"
              density="compact"
              image-size="small"
            ></atomic-commerce-product-list>
            <atomic-commerce-query-error></atomic-commerce-query-error>
          </atomic-layout-section>
      </atomic-commerce-layout>
    </atomic-commerce-interface>
  </body>
</html>
1 Import the Atomic library. This is responsible for handling the web components.
2 Link the Coveo theme stylesheet. This provides the default styling for the web components.
3 Import the Headless for Commerce library to get the sample configuration. When providing your own configuration you won’t need to import this function.
4 The resourceUrl as shown defines the resources for the Coveo integration. These must exist and be configured in your Coveo organization's Coveo Merchandising Hub.
5 Refer to the Coveo Headless documentation for CommerceEngineConfiguration for all configuration options.
6 Initialize the atomic-commerce-interface.
7 The search box for the interface. For additional options refer to Search box component.

Search page

A search page typically consists of a search box and a list of product results, as well as components to filter and navigate the results. Once you know how to build a search box, you can start building a search page. Here is a list of useful Atomic components that can be added to a commerce search page:

Search box component

The search box component is the core of your search interface. It lets users perform product searches by typing and submitting a query. It features built-in support for query suggestions and optional redirection to a search page. For the best user experience, the search box should be clearly visible, typically placed in the upper-center or upper-right section of a page.

You can add the following components as children of the atomic-commerce-search-box component:

When using the atomic-commerce-search-box component on non-search pages, you can add the redirection-url property to create a standalone search box. The search box will redirect users to a results page when they submit a query.