Flexsearch
Built-in document search of Adalt
Adalt supports searching document based on Flexsearch.
As the built-in search of Adalt, It is the default but also recommended option since it's easier to setup and totally free.
If you're using a CMS, you should use the API provided by the CMS instead.
Simple Search
Index with the raw content of document.
Create the Route Handler
Create a Search Dialog
For Adalt UI
Use the default Search Dialog from Adalt UI.
Advanced Search
Returns a more detailed result with matching headings and contents.
It accepts structured data processed from a markdown/MDX document, and index it with Flexsearch. You can extract the structured data using the Structure remark plugin.
It cannot extract content from rehype plugin generated content (remark plugins are supported).
Usage
Same as simple search, but requires the structuredData
property instead of raw content.
Tag Filter
It's useful for implementing versioned docs, or multi-docs similar to this documentation.
For Adalt UI
Configure Tag Filter on search client.
On your search client, pass a tag to the hook.
Custom Algorithm
You can port your own search algorithm by returning a list of SortedResult
from your custom /api/search/route.ts
api endpoint, and you can integrate it
with Adalt UI later.
Prop | Type | Default |
---|---|---|
id | string | - |
url | string | - |
type | "page" | "heading" | "text" | - |
content | string | - |
Internationalization
Use createI18nSearchAPI
for i18n functionality.
Update the route handler
Update search client
Add locale
to search dialog, this will only allow pages with specified
locale to be searched by the user.
For Adalt UI
You can ignore this, Adalt UI handles this when you have i18n configured correctly.
Search Client
useDocsSearch
is a hook that combines debounce value and useSWR
.
Return Type
Prop | Type | Description |
---|---|---|
query | SWRResponse | SWR Query |
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. |
Headless
You can also host the search server on Express or Elysia, without Next.js.
Last updated on