# Fumadocs (Framework Mode, Astro): 自訂搜尋
URL: /zh-TW/docs/astro/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/astro` 會在執行階段提供您頁面的搜尋索引。

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

```ts tab="src/pages/static.json.ts"
import type { APIRoute } from 'astro';
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 prerender = true;

export const GET: APIRoute = async () => 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;
}

const records = JSON.parse(await fs.readFile('dist/static.json', 'utf-8')) as DocumentRecord[];

// sync the records to your search engine

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

```

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

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