feat(web-search): add SearXNG provider (#1166)

支持对接自建/公共 SearXNG 实例作为网络搜索引擎,缓解免费搜索引擎在国内
网络环境下访问受限的问题。

- types: 新增 WebSearchProviderTypeSearxng 与 BaseURL 参数字段;
  类型元数据新增 RequiresBaseURL,前端可动态渲染 Instance URL 表单。
- infrastructure/web_search/searxng.go: 调用 /search?format=json,强制
  utils.ValidateURLForSSRF 校验 base_url,可选 api_key 透传给反代鉴权。
- service: isValidProviderType 与参数校验接入 searxng。
- container: 注册 NewSearxngProvider 工厂。
- frontend: WebSearchSettings 表单根据 requires_base_url 渲染 Instance
  URL 输入框;编辑回填、free 判定同步更新。
- docker: 新增可选 searxng 服务(profile=searxng/full),附带最小化
  settings.yml(启用 JSON 格式、关闭 limiter、关闭遥测),
  docker-compose 默认 SSRF_WHITELIST 包含 searxng 容器名。
- .env.example: 补充 SEARXNG_PORT / SEARXNG_SECRET 说明。

Closes #1166
This commit is contained in:
wizardchen
2026-05-10 22:01:28 +08:00
committed by lyingbug
parent 9dcb61fb45
commit 1110615300
10 changed files with 295 additions and 6 deletions
+15
View File
@@ -21,6 +21,7 @@ const (
WebSearchProviderTypeTavily WebSearchProviderType = "tavily"
WebSearchProviderTypeOllama WebSearchProviderType = "ollama"
WebSearchProviderTypeBaidu WebSearchProviderType = "baidu"
WebSearchProviderTypeSearxng WebSearchProviderType = "searxng"
)
// WebSearchProviderEntity represents a configured web search provider instance for a tenant.
@@ -71,6 +72,9 @@ type WebSearchProviderParameters struct {
APIKey string `yaml:"api_key" json:"api_key,omitempty"`
// Google Custom Search Engine ID (only for Google provider)
EngineID string `yaml:"engine_id" json:"engine_id,omitempty"`
// Base URL for self-hosted search engines (e.g. SearXNG instance URL).
// Validated with utils.ValidateURLForSSRF; private hosts must be added to SSRF_WHITELIST.
BaseURL string `yaml:"base_url" json:"base_url,omitempty"`
// Optional HTTP/HTTPS proxy URL for outbound search requests (e.g. http://host:port); validated with utils.ValidateURLForSSRF.
// Does not replace the search API endpoint; only tunnels traffic to the official APIs.
ProxyURL string `yaml:"proxy_url" json:"proxy_url,omitempty"`
@@ -121,6 +125,8 @@ type WebSearchProviderTypeInfo struct {
RequiresAPIKey bool `json:"requires_api_key"`
// Whether the provider requires an engine ID (e.g., Google CSE)
RequiresEngineID bool `json:"requires_engine_id"`
// Whether the provider requires a user-supplied base URL (e.g., self-hosted SearXNG instance)
RequiresBaseURL bool `json:"requires_base_url"`
// Whether optional proxy_url in parameters is honored for outbound requests
SupportsProxy bool `json:"supports_proxy"`
// Description
@@ -172,6 +178,15 @@ func GetWebSearchProviderTypes() []WebSearchProviderTypeInfo {
Description: "Ollama Cloud web search (requires Ollama API key)",
DocsURL: "https://docs.ollama.com/capabilities/web-search",
},
{
ID: "searxng",
Name: "SearXNG",
RequiresAPIKey: false,
RequiresBaseURL: true,
SupportsProxy: true,
Description: "Self-hosted SearXNG metasearch instance (provide instance URL; private hosts must be SSRF-whitelisted)",
DocsURL: "https://docs.searxng.org/",
},
{
ID: "baidu",
Name: "Baidu",