---
title: "Search Indexing"
description: "Search Indexing is the engine that enables performant full-text search within documentation sites. By transforming raw content—typically Markdown or MDX—into a structured, searchable format, the in..."
last_updated: "2026-07-02T09:46:38.940737+00:00"
canonical_url: "https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/search-subsystem/search-indexing"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [packages/create-app/src/plugins/orama-cloud.ts](https://github.com/blade47/fumadocs/blob/main/packages/create-app/src/plugins/orama-cloud.ts)
- [packages/mdx/src/plugins/index-file.ts](https://github.com/blade47/fumadocs/blob/main/packages/mdx/src/plugins/index-file.ts)
- [packages/core/src/search/orama/create-server.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama/create-server.ts)
- [packages/core/src/mdx-plugins/remark-structure.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/mdx-plugins/remark-structure.ts)
- [packages/core/src/search/server/build-index.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/server/build-index.ts)
- [packages/core/src/search/client/orama-static.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/client/orama-static.ts)
- [packages/openapi/src/generate-file.ts](https://github.com/blade47/fumadocs/blob/main/packages/openapi/src/generate-file.ts)
- [packages/core/src/search/algolia.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/algolia.ts)
- [packages/core/src/search/flexsearch/utils.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/flexsearch/utils.ts)
- [packages/core/src/search/flexsearch.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/flexsearch.ts)
- [packages/asyncapi/src/generate-file.ts](https://github.com/blade47/fumadocs/blob/main/packages/asyncapi/src/generate-file.ts)
- [packages/openapi/src/utils/pages/builder.ts](https://github.com/blade47/fumadocs/blob/main/packages/openapi/src/utils/pages/builder.ts)
- [packages/core/src/source/loader.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/source/loader.ts)
- [packages/content/src/index.ts](https://github.com/blade47/fumadocs/blob/main/packages/content/src/index.ts)
- [packages/core/src/search/client/flexsearch-static.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/client/flexsearch-static.ts)
- [packages/core/src/source/llms.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/source/llms.ts)
- [packages/core/src/search/server/build-doc.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/server/build-doc.ts)
- [packages/preview/src/pages/_api/api/search.ts](https://github.com/blade47/fumadocs/blob/main/packages/preview/src/pages/_api/api/search.ts)
- [packages/core/package.json](https://github.com/blade47/fumadocs/blob/main/packages/core/package.json)
- [packages/core/src/search/client/orama-cloud-legacy.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/client/orama-cloud-legacy.ts)
- [packages/mdx/src/runtime/server.ts](https://github.com/blade47/fumadocs/blob/main/packages/mdx/src/runtime/server.ts)
- [packages/core/src/search/client/orama-cloud.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/client/orama-cloud.ts)
- [packages/create-app/template/+orama-cloud/@app/lib/export-static-indexes.ts](https://github.com/blade47/fumadocs/blob/main/packages/create-app/template/%2Borama-cloud/%40app/lib/export-static-indexes.ts)
- [packages/core/src/source/storage/content.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/source/storage/content.ts)
- [packages/openapi/src/utils/pages/to-static-data.ts](https://github.com/blade47/fumadocs/blob/main/packages/openapi/src/utils/pages/to-static-data.ts)
- [packages/core/src/search/orama/create-db.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama/create-db.ts)
- [packages/core/src/search/orama-cloud-legacy.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama-cloud-legacy.ts)
- [packages/sanity/src/index.ts](https://github.com/blade47/fumadocs/blob/main/packages/sanity/src/index.ts)
- [packages/core/src/search/orama-cloud.ts](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama-cloud.ts)
- [packages/content-collections/src/configuration.ts](https://github.com/blade47/fumadocs/blob/main/packages/content-collections/src/configuration.ts)
</details>

Search Indexing is the engine that enables performant full-text search within documentation sites. By transforming raw content—typically Markdown or MDX—into a structured, searchable format, the indexing system bridges the gap between static documents and dynamic user queries. It solves the performance bottleneck of scanning large text bodies in real-time by generating searchable indices (whether static, in-memory, or hosted by third-party services) during the build process.

The system is architected as a modular pipeline: a "content extractor" (such as `remark-structure`) traverses the AST to collect headings and paragraphs, which are then passed to a "builder" component that converts these into documents compatible with specific search backends (Orama, FlexSearch, or Algolia). This decoupling ensures that documentation authors can swap indexing strategies or backends without rewriting their content source logic.

Crucially, the indexing lifecycle interacts closely with the core `loader` system, which manages the virtual file system and page hierarchy. By centralizing index building, the system guarantees that metadata like breadcrumbs, unique page IDs, and language-specific translations remain consistent across both the rendering layer and the search interface.

## Content Extraction with `remark-structure`

The `remark-structure` plugin acts as the primary content extractor. During the MDX build process, it transforms raw files into `StructuredData`, a data model consisting of `headings` and `contents` arrays.

When `remarkStructure` traverses the MDX tree, it uses a configurable `stringify` function to pull text out of elements. It relies on a `lastHeading` pointer to associate paragraphs with the closest preceding header, creating a flat structure that links text content to its specific context.

> [!TIP]
> Always use `remark-heading` before `remark-structure`. If `remark-structure` finds a heading missing an `hProperties.id`, it will skip that heading, preventing it from being added to the `StructuredData` output.

Sources: [packages/core/src/mdx-plugins/remark-structure.ts:134-199](https://github.com/blade47/fumadocs/blob/main/packages/core/src/mdx-plugins/remark-structure.ts#L134-L199)

## Document Building Pipeline

Once data is extracted, it must be normalized into a backend-agnostic document format. The `buildDocuments` function performs this transformation. It takes a list of `SharedIndex` objects—each containing metadata like titles, URLs, and structured data—and produces an array of `SharedDocument` entities.

The indexing logic iterates through headings and contents, assigning each a unique ID using a counter and creating granular search entries. The `nextId` counter ensures that every individual paragraph or heading has a distinct anchor.

Sources: [packages/core/src/search/server/build-doc.ts:13-68](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/server/build-doc.ts#L13-L68)

## Backend Strategy: Orama

Orama is an in-memory search engine supported natively by the system. The `createDBSimple` and `createDB` (advanced) functions act as the bridge to Orama's API.

For simple search, `createDBSimple` maps the `SharedIndex` into an object matching `simpleSchema` and calls `insertMultiple` to populate the Orama DB.

```mermaid
flowchart TD
    A["Loader Output (Pages)"] --> B["buildIndexDefault (Transform)"]
    B --> C["createDBSimple / createDB"]
    C --> D["insertMultiple (Orama DB)"]
    D --> E["Search API (Ready)"]
```
Sources: [packages/core/src/search/orama/create-db.ts:54-82](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama/create-db.ts#L54-L82)

## Backend Strategy: FlexSearch

FlexSearch, an alternative in-memory backend, is managed through `flexsearch.ts`. It wraps the library's `Document` constructor and exposes an `export` method that serializes the state to a JSON-compatible object.

The system uses a `createDocument` factory that enforces a specific schema, requiring an `id`, `content` field for indexing, and a `tags` array for filtering. Unlike Orama, FlexSearch uses `index.add` inside an `initIndex` routine.

Sources: [packages/core/src/search/flexsearch/utils.ts:70-82](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/flexsearch/utils.ts#L70-L82)

## Integration with Orama Cloud

For larger, production-scale deployments, the system integrates with Orama Cloud via `packages/core/src/search/orama-cloud.ts`. This involves a push-based model where local indexes are transformed into `OramaDocument` types and synced using a `transaction` API.

> [!IMPORTANT]
> The sync process uses a transaction: `index.transaction.open()` starts it, `insertDocuments` adds the batch, and `index.transaction.commit()` finalizes the update. If `autoDeploy` is true, the snapshot is deployed to the production index automatically.

Sources: [packages/core/src/search/orama-cloud.ts:89-99](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/orama-cloud.ts#L89-L99)

## Client-Side Consumption

The client-side search functionality depends on the backend chosen. For static clients (`oramaStaticClient` or `flexsearchStaticClient`), the client fetches a serialized index file.

1. The client performs a `fetch` request to an API endpoint (e.g., `/api/search`).
2. The index database is reconstructed using `load` (for Orama) or `import` (for FlexSearch).
3. The resulting database instance is cached in a `Map` to prevent redundant fetches.

Sources: [packages/core/src/search/client/orama-static.ts:45-82](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/client/orama-static.ts#L45-L82)

## Algolia Integration

Algolia support is handled through a `sync` function in `packages/core/src/search/algolia.ts`. It performs an index replacement: it sets index settings (like searchable attributes and faceting) and then calls `client.replaceAllObjects` to ensure the cloud index perfectly matches the local source state.

Sources: [packages/core/src/search/algolia.ts:49-53](https://github.com/blade47/fumadocs/blob/main/packages/core/src/search/algolia.ts#L49-L53)

## Related

- [Orama Integration](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/search-subsystem/orama-integration)
- [Search Clients](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/search-subsystem/search-clients)


## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/llms.txt) for all pages in this wiki.
