# Fumadocs (Framework Mode, Next.js): 自訂搜尋
URL: /zh-TW/docs/next/search/custom
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/search/custom.zh-TW.mdx

適用於其他搜尋方案。

## 概覽 [#overview]

您可以將任何搜尋引擎整合到 Fumadocs 中。

### 搜尋索引 [#search-indexes]

Fumadocs MDX 會在執行階段提供您頁面的搜尋索引。

若要將其靜態匯出，請新增一個預先算繪的 `static.json` 路由，並在每次建置後以指令碼處理其中的紀錄：

```ts tab="app/static.json/route.ts"
import { source } from '@/lib/source';

async function getDocuments() {
  const documents = [];
  for (const page of source.getPages()) {
    documents.push({
      structured: await page.data.structuredData(),
      url: page.url,
      title: page.data.title,
      description: page.data.description,
    });
  }
  return documents;
}

export const revalidate = false;

export async function GET() {
  return Response.json(await getDocuments());
}

```

```ts tab="scripts/sync-content.ts"
import * as fs from 'node:fs/promises';
import type { StructuredData } from 'fumadocs-core/mdx-plugins';

interface DocumentRecord {
  title: string;
  description?: string;
  url: string;
  structured: StructuredData;
}

// Next.js writes it under `route-cache` when built with an adapter, like on Vercel
const [file] = await Array.fromAsync(fs.glob('.next/server/{app,route-cache/*/*/$}/static.json.body'));
const records = JSON.parse(await fs.readFile(file, 'utf-8')) as DocumentRecord[];

// sync the records to your search engine

console.log(`search updated: ${records.length} records`);

```

```json tab="package.json"
{
  "scripts": {
    "build": "next build && node --env-file-if-exists=.env.local scripts/sync-content.ts"
  }
}
```

`structured` 欄位包含每個頁面的標題與段落，可用來產生精確的搜尋索引。