Integrate Meilisearch into a website#

Meilisearch can be integrated into any website as a web component (search bar) that is linked to a running Meilisearch instance.

Add the search bar to a web page#

To add a search bar to a web page, follow these steps:

  1. Download the docs-searchbar.js package from a content delivery network. You can use this script tag:

    <script src="https://cdn.jsdelivr.net/npm/docs-searchbar.js@2.4.1/dist/cdn/docs-searchbar.min.js"></script>
    
  2. Initialize the search bar by calling the docsSearchBar function with the desired configuration. Here is an example:

    <script>
    let theSearchBar = docsSearchBar({
        hostUrl: 'https://backend.search.pyansys.com',
        apiKey: 'd5271738ba1a75af83748f615aca07f8a73fc353186ff04f28925104b6f49614',
        indexUid: 'ansys-pyansys-sphinx-docs',
        inputSelector: '#q',
        debug: false,
        enhancedSearchInput: false,
        enableDarkMode: 'auto'
    })
    </script>
    
    • Replace the value shown for the hostUrl option with the URL where your search engine is hosted.

    • Replace the value shown for the apiKey option with your public API key.

    • Replace the value shown for the indexUid option with the unique name for the desired index.

    • Modify values for other options (debug, enhancedSearchInput, and enableDarkMode) as needed.

This example shows how to add a search bar to a web page and link it to a Meilisearch instance:

<!doctype html>
<html lang="en">
  <body>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/docs-searchbar.js@latest/dist/cdn/docs-searchbar.min.css"
    />

    <div class="container">
      <div class="col-md-18">
        <input
          type="search"
          placeholder="docs-searchbar input"
          class="form-control"
          id="q"
          autofocus
        />
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/docs-searchbar.js@2.4.1/dist/cdn/docs-searchbar.min.js"></script>

    <script>
      let theSearchBar = docsSearchBar({
        hostUrl: "https://backend.search.pyansys.com",
        apiKey:
          "9c4013dc2ebd88143f99c5de25adbf1552c1dd7108266d3039be1fcffcf76fa8",
        indexUid: "ansys-pyansys-sphinx-docs",
        inputSelector: "#q",
        debug: false,
        enhancedSearchInput: false,
        enableDarkMode: "auto",
      });
    </script>
  </body>
</html>