Query Your Commerce Catalog Content

In most cases, you will want queries originating from a given commerce search interface to target a specific catalog in your Coveo organization. As a result, it will automatically only show targeted products and filter out other objects. This will properly scope the catalog, and ensure searches performed on that page are logged in usage analytics.

Prerequisites

Step 1: Retrieve the Catalog Name

To be able to query a given catalog, you must know its unique name.

Access the Catalogs page, and then locate and copy the desired catalog name from the table.

Step 2: Configure Your Search Interface

Use one of the following methods to ensure that your commerce search interface targets the desired catalog.

The easiest way to query a catalog is to configure a query pipeline rule that transparently adds the catalog identifier to each query.

  1. Access the Query Pipelines page.

  2. Double-click the query pipeline used by your search interface.

  3. Select the Advanced tab, and then click Query parameters.

  4. In the upper-right corner, click Add query parameters rule.

  5. In the Add a Query Parameter Rule panel:

    1. In the Parameter name field, enter commerce.catalogId.

    2. For the String parameter type, in the Parameter value field, enter the catalog name retrieved in step 1.

    3. Click Add Rule.

Queries originating from your commerce search interface will now target the specified catalog.

Method 2: Use a buildingQuery Event Handler

In a JavaScript Search Framework interface, if you would rather modify queries before sending them to the Search API, you can code a buildingQuery event handler that sets the commerce property of the QueryBuilder object as desired.

EXAMPLE
document.addEventListener("DOMContentLoaded", () => {
  // ...
  const root = document.getElementById("search");
  Coveo.$$(root).on("buildingQuery", (e, args) => {
    args.queryBuilder.commerce = { catalogId: "<MY_CATALOG_NAME>" };
  });
  // ...
  Coveo.init(root);
});

Where you would replace <MY_CATALOG_NAME> with the name of your catalog.

What’s Next?

Recommended Articles