ZBSearch (default)
The default search engine powered by ZBSearch.
Overview
Fumadocs configures the ZBSearch search engine out of the box.
It searches through an API endpoint running on the server, or through a statically cached JSON file for static sites.
Setup
Create a search dialog.
The default search dialog uses this client. Re-create it to customize the dialog:
'use client';
import { useFetchSearch } from 'fumadocs-core/search/client';
import {
SearchDialog,
SearchDialogClose,
SearchDialogContent,
SearchDialogHeader,
SearchDialogIcon,
SearchDialogInput,
SearchDialogList,
SearchDialogOverlay,
type SharedProps,
} from 'fumadocs-ui/components/dialog/search';
import { useI18n } from 'fumadocs-ui/contexts/i18n';
export default function DefaultSearchDialog(props: SharedProps) {
const { locale } = useI18n(); // (optional) for i18n
const search = useFetchSearch({
locale,
});
return (
<SearchDialog {...search} {...props}>
<SearchDialogOverlay />
<SearchDialogContent>
<SearchDialogHeader>
<SearchDialogIcon />
<SearchDialogInput />
<SearchDialogClose />
</SearchDialogHeader>
<SearchDialogList />
</SearchDialogContent>
</SearchDialog>
);
}
Replace Search Dialog
Pass your search dialog to <RootProvider /> in your provider component:
'use client';
import type { ReactNode } from 'react';
import { RootProvider } from 'fumadocs-ui/provider/waku';
import SearchDialog from '@/components/search';
export function Provider({ children }: { children: ReactNode }) {
return <RootProvider search={{ SearchDialog }}>{children}</RootProvider>;
}Tag Filter
Optionally, you can add UI for filtering results by tags. Configure Tag Filter on search server and add the following:
'use client';
import {
SearchDialog,
SearchDialogContent,
SearchDialogFooter,
SearchDialogOverlay,
type SharedProps,
TagsList,
TagsListItem,
} from 'fumadocs-ui/components/dialog/search';
import { useState } from 'react';
import { useFetchSearch } from 'fumadocs-core/search/client';
export default function CustomSearchDialog(props: SharedProps) {
const [tag, setTag] = useState<string | undefined>();
const search = useFetchSearch({
tag,
});
return (
<SearchDialog {...search} {...props}>
<SearchDialogOverlay />
<SearchDialogContent>
...
<SearchDialogFooter className="flex flex-row">
<TagsList tag={tag} onTagChange={setTag}>
<TagsListItem value="my-value">My Value</TagsListItem>
</TagsList>
</SearchDialogFooter>
</SearchDialogContent>
</SearchDialog>
);
}How is this guide?
Last updated on
