SearXNG
SearXNG 是開源、自架的 metasearch engine
它不自己建立全網索引,而是聚合多個搜尋引擎的結果
你送出 query
↓
SearXNG 同時發給 Google / Bing / DuckDuckGo / Wikipedia / GitHub 等 251 個來源
↓
聚合、去重、排序
↓
回傳 HTML 或 JSON
SearXNG 不是爬蟲系統,它不 crawl 網頁、不建 index、不做排名
參考:Welcome to SearXNG — SearXNG Documentation
它不是什麼
| 概念 | SearXNG 的實際情況 |
|---|---|
| 搜尋引擎(Google 那種) | ❌ 不自己 crawl 和 index |
| 爬蟲系統 | ❌ 不建立網頁資料庫 |
| Metasearch Engine | ✅ 聚合多個上游結果 |
| 隱私保護 Proxy | ✅ 你的 query 不直接發給 Google |
Search API
SearXNG 提供 /search endpoint,可以回傳結構化資料
GET /search?q=<query>&format=json&engines=google,bing
參數:
q 查詢字串
format html(預設)/ json / csv / rss
engines 指定使用哪些 engine(逗號分隔)
language 語言過濾
pageno 頁碼
回傳的 JSON 結構:
{
"query": "python",
"results": [
{
"title": "...",
"url": "...",
"content": "...",
"engine": "google",
"score": 1.0
}
],
"number_of_results": 1234
}
參考:Search API — SearXNG Documentation
Docker 部署
官方推薦用 Docker Compose 部署
# clone 官方 docker compose 設定
git clone https://github.com/searxng/searxng-docker.git
cd searxng-docker
# 啟動
docker compose up -d
# 停止
docker compose down
預設對外 port:8080
設定檔位置:./searxng/settings.yml
參考:Docker Installation — SearXNG Documentation
settings.yml 重要設定
開啟 JSON format(預設只有 HTML):
search:
formats:
- html
- json # ← 要呼叫 API 必須加這行
server:
bind_address: "0.0.0.0"
secret_key: "your-secret-key-here"
engines:
- name: duckduckgo
disabled: false
- name: google
disabled: false
只改 settings.yml 屬於「部署設定」,不是修改 SearXNG 程式碼
穩定性問題
SearXNG 是聚合器,結果品質取決於上游
| 問題 | 說明 |
|---|---|
| 上游改版 | engine parser 可能突然失效 |
| Rate limit | 被 Google / Bing 限流 |
| CAPTCHA | 高頻查詢觸發驗證 |
| Engine 失效 | 部分 engine 無預警停止回傳 |
| 結果不穩定 | 同一個 query 結果可能不一致 |
→ 這是產品化時最大的風險
Public Instance 不適合正式產品
網路上有很多公開 SearXNG instance,但不建議依賴它們
風險:
不保證 uptime
可能關閉 JSON API(官方文件有提醒這點)
可能限流你的 IP
你不知道對方的 engine 設定
隱私與合規不可控
→ 正式產品應自架 SearXNG instance
AGPL-3.0 授權
SearXNG 採用 GNU Affero General Public License v3.0
情境 A:透過 HTTP 呼叫自架的 unmodified SearXNG
→ 通常風險較低
→ 你的 backend / agent 不需要開源
情境 B:修改 SearXNG 原始碼,並作為網路服務對外提供
→ AGPL 第 13 節要求提供修改後的 source code
這不是法律意見,產品化前要讓法務確認
建議的架構
你的 Agent / MCP Server / FastAPI
↓ HTTP only
自架 unmodified SearXNG container(Docker)
↓
上游 search engines(Google, Bing, DDG...)
可以做的:
- 用 Docker 部署原版 SearXNG
- 只改 settings.yml
- 透過
/search?format=json呼叫 - 在你的 backend 做 normalization / rerank / citation
避免:
- 直接改 SearXNG 原始碼
- 把 SearXNG code copy 進自己的專案
- 依賴 public instance