# Search Services

Use an external search service.

A search service hosts the index instead of the [built-in search](/search), and adds features like analytics, synonyms or semantic search. Each service has a plugin, which uploads your pages when the site builds and shows the service's results in the search dialog.

A service plugin also takes the built-in search's options, like `filter`, `buildIndex`, `tags` and the [dialog options](/search#dialog-options). The build uploads the pages with `writeApiKey`.

<Callout type="warn" title="Keep Write Keys Out of the Code">
Read `writeApiKey` from a build environment variable, never from a string in the code. When the variable is empty, the build warns and skips the upload, so the site searches the index as it is.
</Callout>

## Algolia [#algolia]

Install the plugin with the service's client:

```npm
npm i @vuesho/algolia algoliasearch
```

Turn off the preset's search, and add `algoliaPlugin()` with your application's keys:

```ts title="vuesho.config.ts"
import { algoliaPlugin } from "@vuesho/algolia"; // [!code ++]
import { createSite, recommendedPreset } from "vuesho/config";
import { defineDocs } from "vuesho/content";

const docs = defineDocs();

export default createSite(docs.toSource()).plugins(
  recommendedPreset({ search: false }), // [!code highlight]
  // [!code ++:7]
  algoliaPlugin({
    appId: "YOUR_APP_ID",
    // The search-only key, which the browser searches with.
    apiKey: "YOUR_SEARCH_API_KEY",
    indexName: "docs",
    writeApiKey: process.env.ALGOLIA_WRITE_API_KEY,
  }),
);
```

### AlgoliaPluginOptions

| Prop           | Type                   | Description                                                                                                                                                                                             |
| -------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `appId`        | `string`               | The Algolia application ID.                                                                                                                                                                             |
| `apiKey`       | `string`               | A search-only API key, which the dialog uses.                                                                                                                                                           |
| `indexName`    | `string`               | The index, or on a site with languages the prefix for each language's index, like `docs_cn`.                                                                                                            |
| `writeApiKey?` | `string \| undefined`  | An API key that can write the index, like `process.env.ALGOLIA_WRITE_API_KEY`. Each build replaces the index's records with the site's pages. Without it, the site searches an index you fill yourself. |
| `showAlgolia?` | `boolean \| undefined` | Shows the "Powered by Algolia" label, which the free plan requires. Default: `false`                                                                                                                    |

`vuesho build` uploads the pages to the index. With multiple languages, each language has its own index, named with its key, like `docs_cn`.

## Orama Cloud [#orama-cloud]

Install the plugin with the service's client:

```npm
npm i @vuesho/orama-cloud @orama/core
```

```ts title="vuesho.config.ts"
import { oramaCloudPlugin } from "@vuesho/orama-cloud"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset({ search: false }), // [!code highlight]
  // [!code ++:7]
  oramaCloudPlugin({
    projectId: "YOUR_PROJECT_ID",
    // The public key, which the browser searches with.
    apiKey: "YOUR_PUBLIC_API_KEY",
    datasource: "YOUR_DATASOURCE_ID",
    writeApiKey: process.env.ORAMA_PRIVATE_API_KEY,
  }),
);
```

### OramaCloudPluginOptions

| Prop             | Type                                           | Description                                                                                                                                                                                                      |
| ---------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `projectId`      | `string`                                       | The Orama Cloud project ID.                                                                                                                                                                                      |
| `apiKey`         | `string`                                       | A public API key for the project, which the dialog uses.                                                                                                                                                         |
| `datasource`     | `string`                                       | The datasource ID for the pages, or one per language by key on a site with languages.                                                                                                                            |
| `writeApiKey?`   | `string \| undefined`                          | A private API key for the project, like `process.env.ORAMA_PRIVATE_API_KEY`. Each build replaces the datasource's documents with the site's pages. Without it, the site searches a datasource you fill yourself. |
| `deploy?`        | `boolean \| undefined`                         | `false` uploads a build's documents to a temporary index of the datasource and leaves the live index as it is, like `autoDeploy: false` in Fumadocs. Default: `true`                                             |
| `showOrama?`     | `boolean \| undefined`                         | Shows the "Powered by Orama" label. Default: `true`                                                                                                                                                              |
| `searchOptions?` | `Partial<OramaCloudSearchParams> \| undefined` | Parameters for each dialog search, like `{ threshold: 0 }`, on the language's datasource.                                                                                                                        |

`vuesho build` uploads the pages to the datasource and deploys it. With multiple languages, `datasource` takes an ID per language, like `{ en: "…", cn: "…" }`.

An index that the Orama Cloud crawler fills needs a custom dialog, as [Search](/search#searching-an-external-index) shows.

## Meilisearch [#meilisearch]

The plugin works with a self-hosted Meilisearch instance and with Meilisearch Cloud.

Install the plugin with the service's client:

```npm
npm i @vuesho/meilisearch meilisearch
```

`apiKey` is sent to the browser, so it must be a search key, as the [Meilisearch security guide](https://www.meilisearch.com/docs/learn/security/basic_security) explains:

```ts title="vuesho.config.ts"
import { meilisearchPlugin } from "@vuesho/meilisearch"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset({ search: false }), // [!code highlight]
  // [!code ++:7]
  meilisearchPlugin({
    host: "YOUR_INSTANCE_URL",
    // The search key, which the browser searches with.
    apiKey: "YOUR_SEARCH_API_KEY",
    indexName: "docs",
    writeApiKey: process.env.MEILISEARCH_ADMIN_KEY,
  }),
);
```

### MeilisearchPluginOptions

| Prop           | Type                  | Description                                                                                                                                                                        |
| -------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `host`         | `string`              | The Meilisearch instance's URL.                                                                                                                                                    |
| `apiKey`       | `string`              | A search key, which the dialog uses.                                                                                                                                               |
| `indexName`    | `string`              | The index of the pages. On a site with languages, it holds every language's pages, and the dialog searches those in the page's language.                                           |
| `writeApiKey?` | `string \| undefined` | An admin key, like `process.env.MEILISEARCH_ADMIN_KEY`. Each build replaces the index's documents with the site's pages. Without it, the site searches an index you fill yourself. |

`vuesho build` replaces the index's documents with your pages. With multiple languages, one index holds every language's pages, and the dialog searches only the current language.

## Typesense [#typesense]

The plugin works with a self-hosted Typesense server and with Typesense Cloud.

Install the plugin with the service's client:

```npm
npm i @vuesho/typesense typesense
```

```ts title="vuesho.config.ts"
import { typesensePlugin } from "@vuesho/typesense"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset({ search: false }), // [!code highlight]
  // [!code ++:7]
  typesensePlugin({
    nodes: [{ url: "YOUR_SERVER_URL" }],
    // The search-only key, which the browser searches with.
    apiKey: "YOUR_SEARCH_ONLY_API_KEY",
    collectionName: "docs",
    writeApiKey: process.env.TYPESENSE_ADMIN_API_KEY,
  }),
);
```

### TypesensePluginOptions

| Prop             | Type                                                                                   | Description                                                                                                                                                                                                            |
| ---------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nodes`          | `NodeConfiguration[] \| NodeConfigurationWithHostname[] \| NodeConfigurationWithUrl[]` | The server's or cluster's nodes, like `[{ url: "https://xyz.a1.typesense.net" }]`.                                                                                                                                     |
| `apiKey`         | `string`                                                                               | A search-only key, which the dialog uses.                                                                                                                                                                              |
| `collectionName` | `string`                                                                               | The collection for the pages: an alias that each build points at a new collection. On a site with languages, each language has its own, named after it, like `docs_cn`.                                                |
| `writeApiKey?`   | `string \| undefined`                                                                  | An admin key, like `process.env.TYPESENSE_ADMIN_API_KEY`. Each build replaces the collection with the site's pages and keeps its synonyms and curations. Without it, the site searches a collection you fill yourself. |

`collectionName` is an alias, so a search never reads a half-uploaded index, and the synonyms and curations carry over to each build. With multiple languages, each language has its own alias, like `docs_cn`.

## Mixedbread [#mixedbread]

[Mixedbread](https://www.mixedbread.com) finds pages by meaning, not only by their words. Your server searches the store with a key that never reaches the browser, so the site needs a [server](/deploying).

Install the plugin with the service's client:

```npm
npm i @vuesho/mixedbread @mixedbread/sdk
```

The server searches with the key in the `MXBAI_API_KEY` environment variable, or with `apiKey`:

```ts title="vuesho.config.ts"
import { mixedbreadPlugin } from "@vuesho/mixedbread"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset({ search: false }), // [!code highlight]
  // [!code ++:4]
  mixedbreadPlugin({
    storeIdentifier: "YOUR_STORE_ID",
    writeApiKey: process.env.MXBAI_WRITE_API_KEY,
  }),
);
```

### MixedbreadPluginOptions

| Prop              | Type                                                                      | Description                                                                                                                                                                                              |
| ----------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `delayMs?`        | `number \| undefined`                                                     | How long the dialog waits after a keystroke before it searches, in ms. Each search is a request to Mixedbread. Default: `300`                                                                            |
| `storeIdentifier` | `string`                                                                  | The ID or name of the store that holds the pages. On a site with languages, it holds every language's pages.                                                                                             |
| `apiKey?`         | `string \| undefined`                                                     | An API key that can search the store. Defaults to the `MXBAI_API_KEY` environment variable. The server searches with it, so it never reaches the browser.                                                |
| `writeApiKey?`    | `string \| undefined`                                                     | An API key that can write the store, like `process.env.MXBAI_WRITE_API_KEY`. Each build uploads the changed pages and deletes the removed ones. Without it, the site searches a store you fill yourself. |
| `topK?`           | `number \| undefined`                                                     | The most results a search returns, which a request's `limit` can only lower. Default: `10`                                                                                                               |
| `rerank?`         | `boolean \| undefined`                                                    | Ranks the results again for relevance, which adds latency.                                                                                                                                               |
| `rewriteQuery?`   | `boolean \| undefined`                                                    | Rewrites the query for better results, which adds latency.                                                                                                                                               |
| `scoreThreshold?` | `number \| undefined`                                                     | The lowest score a result can have.                                                                                                                                                                      |
| `transform?`      | `((results: FoundChunk[], query: string) => SortedResult[]) \| undefined` | Turns the chunks a search found into results, like for a store you fill yourself in another shape.                                                                                                       |

With multiple languages, one store holds every language's pages, and a search returns only the current language's.

## Custom Fields [#custom-fields]

Algolia, Orama Cloud and Typesense store the extra fields that [`buildIndex`](/search#customizing-the-index) adds to a page's index, for ranking and filters in the service. Meilisearch and Mixedbread store only the built-in fields.

```ts title="vuesho.config.ts"
import { algoliaPlugin } from "@vuesho/algolia";
import { buildIndexDefault } from "vuesho/search";

algoliaPlugin({
  appId: "YOUR_APP_ID",
  apiKey: "YOUR_SEARCH_API_KEY",
  indexName: "docs",
  writeApiKey: process.env.ALGOLIA_WRITE_API_KEY,
  async buildIndex(page) {
    const index = await buildIndexDefault.call(this, page);
    // A `version` field on each record of the page, like "v2" for `v2/install.md`.
    return { ...index, version: page.path.split("/")[0] }; // [!code highlight]
  },
});
```
