介绍
# SearXNG Web Search
使用自托管的 SearXNG 实例搜索网络。此技能通过 SearXNG JSON API 提供对网络搜索结果的访问,并内置了速率限制、错误处理和结果格式化功能。
## When to Use
当您需要以下情况时使用此技能: - 查找当前信息或最新新闻 - 研究超出您知识截止日期的主题 - 查找文档或技术参考资料 - 核实事实或检查当前状态 - 查找有关特定主题的 URL 或资源 - 搜索代码示例或解决方案
## Configuration
将 `SEARXNG_URL` 环境变量设置为您的 SearXNG 实例:
```bash export SEARXNG_URL="http://localhost:8888" ```
如果未设置,则使用默认值 (http://localhost:8888)。
## Usage
使用您的查询执行搜索脚本:
```bash bb scripts/search.clj "your search query" ```
### Advanced Options
作为 JSON 传递附加参数:
```bash bb scripts/search.clj "your query" '{"category": "news", "time_range": "day", "num_results": 10}' ```
可用选项: - `category` - 按类别筛选:general(综合)、news(新闻)、images(图片)、videos(视频)、it(科技)、science(科学) - `time_range` - 时间筛选:day(天)、week(周)、month(月)、year(年) - `language` - 语言代码(默认:en) - `num_results` - 要返回的结果数量(默认:5)
## Output Format
该脚本将格式化的搜索结果作为文本返回:
``` Search Results for "your query" Found 42 total results
1. Result Title [Score: 1.85] URL: https://example.com/page Description snippet from the page... Engines: google, bing
2. Another Result [Score: 1.62] ... ```
## Error Handling
该脚本能够优雅地处理常见错误: - 网络超时(30秒超时) - SearXNG 不可用(清晰的错误消息) - 无效查询(错误详情) - 速率限制(429 响应) - 空结果(信息性消息)
## Rate Limiting
该脚本实现了基本的速率限制: - 请求之间最少间隔 1 秒 - 使用基于文件系统的状态(`.searxng-last-request`) - 防止意外滥用
## Examples
### Basic Search ```bash bb scripts/search.clj "NixOS configuration" ```
### News Search ```bash bb scripts/search.clj "AI developments" '{"category": "news", "time_range": "week"}' ```
### Technical Search ```bash bb scripts/search.clj "babashka http client" '{"category": "it", "num_results": 3}' ```
### Recent Results Only ```bash bb scripts/search.clj "product launch" '{"time_range": "day"}' ```
## Troubleshooting
**"SEARXNG_URL not set"** - 设置环境变量:`export SEARXNG_URL="http://localhost:8888"`
**Connection timeout** - 检查 SearXNG 是否正在运行:`curl $SEARXNG_URL/search?q=test&format=json` - 验证防火墙设置 - 检查服务状态:`systemctl status searx`
**Empty results** - 尝试更广泛的查询 - 移除筛选器后重试 - 检查 SearXNG 日志:`journalctl -u searx -n 50`
**Rate limit errors** - 搜索之间等待几秒钟 - 该脚本会自动强制执行至少 1 秒的延迟
## Implementation Notes
搜索脚本 (`scripts/search.clj`) 使用: - `babashka.http-client` 处理 HTTP 请求 - Clojure 的 `cheshire.core` 进行 JSON 解析 - 基于文件系统的速率限制 - 30 秒超时并提供适当的错误消息 - 结果评分和排序,以将最佳结果排在前面
有关详细的 API 文档,请参阅 `references/api-guide.md`。