Flexsearch
Built-in document search of Next Docs
Next Docs supports searching document based on Flexsearch.
As the bulit-in search of Next Docs, It is the default but also recommended option since it's easier to setup and totally free.
Usage
Note: If you're using a CMS, you should use the API provided by the CMS instead.
- Create the API Route.
- Create a Search Dialog.
createSearchAPI
Create a GET route handler, that supports simple
and advanced
search.
createI18nSearchAPI
Create a GET route handler with i18n functionality.
useDocsSearch
A hook that combined 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. |
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 Next Docs UI.
Prop | Type | Default |
---|---|---|
id | string | - |
url | string | - |
type | enum | - |
content | string | - |
Advanced Search
Returns a more detailed result with matching headings and contents.
It accepts structured data procesed from a markdown/MDX document, and index it with
Flexsearch. You can extract the structured data using the Structure remark plugin or structure()
function.
Notice that it cannot extract content from rehype-specific content (remark plugins are supported)
Usage
Same as simple search, but requires the structuredData
property.
Tag Filter
It's useful for implementing versioned docs, or multi-docs similar to this documentation.
Next Docs UI's Search Dialog doesn't support tag filter.
Last updated on