Coveo JavaScript Search Framework

2.10125.2 · maintenance · verified Sun Apr 19

The Coveo JavaScript Search Framework, currently at version 2.10125.2, provides a comprehensive set of pre-built UI components for creating search interfaces powered by the Coveo Platform. Developed in TypeScript and shipping with integrated type definitions, it facilitates robust and type-safe development. The framework exhibits a very frequent release cadence, with minor versions often released daily, reflecting active maintenance. Its core differentiator lies in a declarative approach to building search UIs, primarily utilizing HTML data attributes for components and a global `Coveo` object for programmatic control and initialization. This abstracts much of the direct interaction with the underlying search API. While actively maintained, Coveo now advises developers to use its more modern, framework-agnostic Atomic or Headless libraries for new projects, as `coveo-search-ui` is explicitly in maintenance mode.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the foundational setup of a Coveo search interface using `coveo-search-ui`. It includes configuring the cloud endpoint with an API key and organization ID, defining essential search components via HTML classes, and initializing the framework.

import * as Coveo from 'coveo-search-ui';

// Ensure Coveo CSS is loaded (example for Webpack/bundlers)
// import 'coveo-search-ui/bin/css/CoveoFullSearch.min.css';

// Basic HTML structure for the search interface
// This would typically be in an HTML file or injected into the DOM.
const appRoot = document.getElementById('search-root') || document.createElement('div');
appRoot.id = 'search-root';
document.body.appendChild(appRoot);

appRoot.innerHTML = `
  <div class="CoveoSearchInterface" id="search">
    <div class="CoveoSearchbox"></div>
    <div class="CoveoResultList"></div>
    <div class="CoveoPager"></div>
  </div>
`;

const organizationId = process.env.COVEO_ORGANIZATION_ID ?? 'YOUR_ORG_ID';
const accessToken = process.env.COVEO_ACCESS_TOKEN ?? 'YOUR_API_KEY'; // Ensure this key has 'Search - Execute queries' privilege
const searchHub = process.env.COVEO_SEARCH_HUB ?? 'default';

(async () => {
  // Configure the search endpoint
  Coveo.SearchEndpoint.configureCloudEndpoint(
    organizationId,
    accessToken,
    searchHub
  );

  // Initialize the framework on the root element of the search interface
  // For token renewal, pass a function that returns a new token.
  Coveo.init(document.getElementById('search') as HTMLElement, {
    // Additional options can be passed here
    // For example, to handle token renewal:
    // accessToken: () => fetch('/api/renew-token').then(res => res.text())
  });

  console.log('Coveo Search Interface initialized.');
})();

view raw JSON →