Built-in Search
Built-in document search of Fumadocs
Fumadocs supports searching document based on Orama.
As the built-in search of Fumadocs, It is the default but also recommended option since it's easier to setup and totally free.
If you're using a CMS, you may use the API provided by the CMS instead.
Setup
From Source
Create a route handler from Source API.
From Search Indexes
Pass search indexes to the function, see type information for required properties.
For content indexing, each index needs a structuredData
field.
It can be processed from Markdown/MDX document, or provided by your content source (e.g. Fumadocs MDX).
You can extract structured data using the Structure remark plugin.
Client
You can query it using:
-
Fumadocs UI: The built-in Search UI supports it out-of-the-box.
-
Search Client:
Tag Filter
Support filtering by tag, it's useful for implementing multi-docs similar to this documentation.
and update your search client:
-
Fumadocs UI: Configure Tag Filter on Search UI.
-
Search Client: pass a tag to the hook.
Index by Content
Index with the raw content of document (unrecommended).
Internationalization
Update the route handler (From Source)
Enable i18n from source object (in loader
function).
Update the route handler (From Search Indexes)
Use createI18nSearchAPI
for i18n functionality.
Update search client
For Fumadocs UI
You can ignore this, Fumadocs UI handles this when you have i18n configured correctly.
Add locale
to the search client, this will only allow pages with specified locale to be searchable by the user.
Special Languages
Orama requires extra configurations for Chinese, Japanese, and some other languages.
See Orama Docs for more details.
Static Export
To work with Next.js static export, use staticGET
from search server.
staticGET
is also available on createSearchAPI
.
and update your search clients:
-
Fumadocs UI:
You can pass search options to Root Provider. See
options
. -
Search Client:
On your search client, use
static
instead offetch
.
Be Careful
Static Search requires clients to download the exported search indexes. For large docs sites, its size can be really big.
Especially with i18n (e.g. Chinese tokenizers), the bundle size of tokenizers can exceed ~500MB. You should use 3rd party solutions like Algolia for these cases.
Search Client
useDocsSearch
is a hook to search documents using the built-in search clients.
Client
Choose the client to use.
Type | Description |
---|---|
fetch (default) | send HTTP request to a search server with fetch |
static | Load search map on client-side and query them |
algolia | Use Algolia Search (See Algolia |
Return Type
Prop | Type | Description |
---|---|---|
query | Query | Query status and results |
search | string | Searching text (not debounced) |
setSearch | (v: string) => void | Set searching text |
Response Data
Type | |
---|---|
empty | If the searching text is empty or blank |
SortedResult[] | Array of matching pages, headings and contents. |
Custom Algorithm
You can port your own search algorithm by returning a list of SortedResult
from your custom /api/search/route.ts
route handler (API Endpoint). You can also integrate it
with Fumadocs UI.
Prop | Type | Default |
---|---|---|
id | string | - |
url | string | - |
type | "page" | "heading" | "text" | - |
content | string | - |
Headless
You can host the search server on Express or Elysia, without Next.js.
Last updated on