searxng-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SearXNG Search Skill

SearXNG搜索技能

Search the web using a SearXNG instance via its API.
通过API调用SearXNG实例进行网页搜索。

Configuration

配置

The config file is read from
$XDG_CONFIG_HOME/agents/searxng.json
(defaults to
~/.config/agents/searxng.json
).
配置文件读取路径为
$XDG_CONFIG_HOME/agents/searxng.json
(默认路径为
~/.config/agents/searxng.json
)。

Config fields

配置字段

FieldTypeRequiredDescription
base_url
string
YesSearXNG instance URL (no trailing slash)
auth
object
NoAuth config object (see below)
auth.type
string
If auth
"bearer"
or
"basic"
auth.token
string
If bearerBearer token value (supports
$ENV_VAR
)
auth.user
string
If basicBasic auth username
auth.pass
string
If basicBasic auth password
headers
object
NoKey-value pairs of additional HTTP headers
default_language
string
NoDefault language code (e.g.
"en"
,
"zh-CN"
)
default_categories
string[]
NoDefault categories (e.g.
["general", "news"]
)
default_engines
string[]
NoDefault engines (e.g.
["google", "duckduckgo"]
)
default_safesearch
number
NoDefault safe search level:
0
,
1
,
2
default_time_range
string
NoDefault time range:
"day"
,
"month"
,
"year"
default_max_results
number
NoMax results to display (default:
5
)
timeout
number
NoRequest timeout in seconds (default:
30
)
字段类型是否必填说明
base_url
string
SearXNG实例URL(末尾不要加斜杠)
auth
object
认证配置对象(见下文)
auth.type
string
配置了auth时必填可选值
"bearer"
"basic"
auth.token
string
认证类型为bearer时必填Bearer令牌值(支持读取
$ENV_VAR
环境变量)
auth.user
string
认证类型为basic时必填Basic认证用户名
auth.pass
string
认证类型为basic时必填Basic认证密码
headers
object
额外HTTP请求头的键值对
default_language
string
默认语言代码(例如
"en"
"zh-CN"
default_categories
string[]
默认搜索分类(例如
["general", "news"]
default_engines
string[]
默认调用的搜索引擎(例如
["google", "duckduckgo"]
default_safesearch
number
默认安全搜索等级:
0
1
2
default_time_range
string
默认搜索时间范围:
"day"
"month"
"year"
default_max_results
number
最大展示结果数(默认值:
5
timeout
number
请求超时时间,单位为秒(默认值:
30

Example config (Bearer auth)

配置示例(Bearer认证)

json
{
  "base_url": "https://searx.example.com",
  "auth": {
    "type": "bearer",
    "token": "your-token-here"
  },
  "default_categories": ["general"],
  "default_engines": ["google", "duckduckgo", "brave"],
  "default_max_results": 10,
  "headers": {
    "X-Custom-Header": "value"
  }
}
json
{
  "base_url": "https://searx.example.com",
  "auth": {
    "type": "bearer",
    "token": "your-token-here"
  },
  "default_categories": ["general"],
  "default_engines": ["google", "duckduckgo", "brave"],
  "default_max_results": 10,
  "headers": {
    "X-Custom-Header": "value"
  }
}

Example config (Basic auth)

配置示例(Basic认证)

json
{
  "base_url": "https://searx.example.com",
  "auth": {
    "type": "basic",
    "user": "admin",
    "pass": "password"
  },
  "default_safesearch": 1
}
json
{
  "base_url": "https://searx.example.com",
  "auth": {
    "type": "basic",
    "user": "admin",
    "pass": "password"
  },
  "default_safesearch": 1
}

Usage

使用方法

Run the search script:
bash
python3 scripts/search.py [OPTIONS] <query>
运行搜索脚本:
bash
python3 scripts/search.py [OPTIONS] <query>

Options

可选参数

FlagDescription
-c, --categories
Comma-separated categories (
general
,
news
,
images
,
videos
,
music
,
files
,
it
,
science
,
social media
)
-e, --engines
Comma-separated engines (
google
,
duckduckgo
,
bing
, etc.)
-l, --language
Language code (
en
,
zh-CN
,
ja
, etc.)
-p, --page
Page number (default: 1)
-t, --time-range
Time range:
day
,
month
,
year
-n, --max-results
Max results to show (overrides config default)
-s, --safesearch
Safe search:
0
(off),
1
(moderate),
2
(strict)
标识说明
-c, --categories
逗号分隔的搜索分类(可选值:
general
news
images
videos
music
files
it
science
social media
-e, --engines
逗号分隔的搜索引擎(可选值:
google
duckduckgo
bing
等)
-l, --language
语言代码(可选值:
en
zh-CN
ja
等)
-p, --page
页码(默认值:1)
-t, --time-range
搜索时间范围:
day
month
year
-n, --max-results
最大返回结果数(覆盖配置文件中的默认值)
-s, --safesearch
安全搜索等级:
0
(关闭)、
1
(适中)、
2
(严格)

Examples

示例

bash
undefined
bash
undefined

Basic search

基础搜索

python3 scripts/search.py "SearXNG documentation"
python3 scripts/search.py "SearXNG documentation"

Search news from the last day

搜索最近一天的新闻

python3 scripts/search.py -c news -t day "latest tech news"
python3 scripts/search.py -c news -t day "latest tech news"

Search with specific engines, page 2

使用指定搜索引擎搜索,获取第2页结果

python3 scripts/search.py -e google,duckduckgo -p 2 "rust programming"
python3 scripts/search.py -e google,duckduckgo -p 2 "rust programming"

Search in Chinese with more results

中文搜索,返回更多结果

python3 scripts/search.py -l zh-CN -n 10 "开源搜索引擎"
undefined
python3 scripts/search.py -l zh-CN -n 10 "开源搜索引擎"
undefined

Best Practices

最佳实践

  • Technical topics (programming, software, science, IT, etc.): Always use English as both the query language and search language (
    -l en
    ), regardless of the user's input language. Translate the query to English if needed. English results are more comprehensive and up-to-date for technical content.
  • Chinese lifestyle topics (food, travel, shopping, local services, social trends, etc.): In addition to the default search, run a second search with
    -e baidu,sogou -l zh-CN
    using a Chinese query to capture China-specific results. Merge and deduplicate results before presenting to the user.
  • 技术类主题(编程、软件、科学、IT等):无论用户输入的是什么语言,查询语句和搜索语言都统一使用英文(
    -l en
    ),必要时将查询内容翻译成英文。技术类内容的英文搜索结果更全面、时效性更强。
  • 中文生活类主题(美食、旅行、购物、本地服务、社会热点等):除了默认搜索外,再使用中文查询词额外执行一次带
    -e baidu,sogou -l zh-CN
    参数的搜索,获取中文生态专属结果。合并结果并去重后再展示给用户。

Workflow

工作流

  1. User asks to search for something
  2. Determine the topic type:
    • Technical: translate query to English if needed, search with
      -l en
    • Chinese lifestyle: run the default search first, then an additional search with
      -e baidu,sogou -l zh-CN
  3. Run
    scripts/search.py
    with the query and any relevant filters
  4. Present results to the user in a readable format
  5. If user wants more results, use
    -p
    for pagination or
    -n
    for more per page
  1. 用户提出搜索需求
  2. 判断主题类型:
    • 技术类:必要时将查询词翻译成英文,使用
      -l en
      参数搜索
    • 中文生活类:先执行默认搜索,再额外执行带
      -e baidu,sogou -l zh-CN
      参数的搜索
  3. 搭配查询词和相关筛选参数运行
    scripts/search.py
  4. 将结果以易读格式展示给用户
  5. 如果用户需要更多结果,使用
    -p
    参数翻页,或使用
    -n
    参数提高单页返回结果数量