# Fumadocs (Framework Mode, Astro): Mixedbread
URL: /zh-TW/docs/astro/search/mixedbread
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/search/mixedbread.zh-TW.mdx

在 Fumadocs UI 中使用 Mixedbread。

## 設定 [#setup]

Mixedbread 搜尋會在請求時於您的伺服器上執行，因此不適用於靜態網站。

Fumadocs CLI 可以幫您完成設定，它會建立搜尋對話方塊、搜尋路由、`static.json` 路由，以及一個在每次建置後同步儲存區的指令碼：

```package-install
npx @fumadocs/cli feature search --provider mixedbread
```

或手動設定：

1. 整合 [Mixedbread Search](/docs/headless/search/mixedbread)。

2. 建立搜尋對話方塊元件。

   ```tsx title="components/search.tsx"
   'use client';

   import {
     SearchDialog,
     SearchDialogClose,
     SearchDialogContent,
     SearchDialogFooter,
     SearchDialogHeader,
     SearchDialogIcon,
     SearchDialogInput,
     SearchDialogList,
     SearchDialogOverlay,
     type SharedProps,
   } from 'fumadocs-ui/components/dialog/search';
   import { useFetchSearch } from 'fumadocs-core/search/client';
   import { useI18n } from 'fumadocs-ui/contexts/i18n';

   export default function CustomSearchDialog(props: SharedProps) {
     const { locale } = useI18n(); // (optional) for i18n
     const search = useFetchSearch({
       api: '/api/search',
       locale,
       // every search is a request to Mixedbread
       delayMs: 300,
     });

     return (
       <SearchDialog {...search} {...props}>
         <SearchDialogOverlay />
         <SearchDialogContent>
           <SearchDialogHeader>
             <SearchDialogIcon />
             <SearchDialogInput />
             <SearchDialogClose />
           </SearchDialogHeader>
           <SearchDialogList />
           <SearchDialogFooter>
             <a
               href="https://mixedbread.com"
               rel="noreferrer noopener"
               className="ms-auto text-xs text-fd-muted-foreground"
             >
               Search powered by Mixedbread
             </a>
           </SearchDialogFooter>
         </SearchDialogContent>
       </SearchDialog>
     );
   }
   ```

### 替換搜尋對話方塊 [#replace-search-dialog]

您的 provider 元件已會將 `src/components/search.tsx` 傳入 [`<RootProvider />`](/docs/ui/layouts/root-provider)，因此只要替換該檔案即可：

```tsx title="src/components/provider.tsx"
import { navigate } from 'astro:transitions/client';
import type { ReactNode } from 'react';
import { RootProvider } from 'fumadocs-ui/provider/astro';
import SearchDialog from '@/components/search';

export interface ProviderProps {
  pathname: string;
  params: Record<string, string | undefined>;
  children?: ReactNode;
}

export function Provider({ pathname, params, children }: ProviderProps) {
  return (
    <RootProvider
      pathname={pathname}
      params={params}
      navigate={navigate}
      // [!code highlight]
      search={{ SearchDialog }}
    >
      {children}
    </RootProvider>
  );
}
```

### 標籤篩選 [#tag-filter]

您也可以視需要加入依標籤篩選結果的 UI。請在搜尋伺服器上設定[標籤篩選](/docs/headless/search/mixedbread#tag-filter)，並加入以下內容：

```tsx
'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) {
  // [!code ++]
  const [tag, setTag] = useState<string | undefined>();
  const search = useFetchSearch({
    tag, // [!code ++]
  });

  return (
    <SearchDialog {...search} {...props}>
      <SearchDialogOverlay />
      <SearchDialogContent>
        ...
        <SearchDialogFooter className="flex flex-row">
          {/* [!code ++:3] */}
          <TagsList tag={tag} onTagChange={setTag}>
            <TagsListItem value="my-value">My Value</TagsListItem>
          </TagsList>
        </SearchDialogFooter>
      </SearchDialogContent>
    </SearchDialog>
  );
}
```