两句话总结:
不使用 /etc/searxng/settings.yml 配置,改用 /usr/local/searxng/searx/setttings.yml 指定配置。Open WebUI中不要填写 域名过滤列表 项。
最近基于Open WebUI v0.5.20 搭建了一个LLM前端,想要通过searXNG实现联网搜索,按照文档操作后始终无法实现搜索功能。报错有以下几类:
- 找到0个结果
- 搜索错误
查看日志并使用curl直接请求url进行测试
curl 'http://localhost:8080/search?q=Apple+Today&format=json'
返回内容显示没有获取到搜索结果,超时的引擎有xxx,xxx。大概是使用了无法连接的引擎,根据官网文档,修改了/etc/searxng/settings.yml,但是无法生效,依然不能使用设置的引擎。查看searXNG的源码(GitHub),发现配置文件加载是先读取 searx下的settings.yml (在Docker镜像中就是 /usr/local/searxng/searx/settings.yml),再读取环境变量中指定的路径中的settings.yml(在Docker中是/etc/searxng/settings.yml),因此可能导致配置文件读取有误,因此不如直接修改searx下第一次读取的配置文件。
修改后能curl能成功使用配置文件中的搜索引擎搜索结果,大概如下
{"query": "Apple Today", "number_of_results": 250000, "results": [{"url": "https://www.apple.com.cn/today/", "title": "Today at Apple - Apple (\u4e2d\u56fd)", "content": "\u5b66\u4e60\u3001\u521b\u4f5c\u3001\u83b7\u53d6\u7075\u611f\uff0c\u5c3d\u5728 Apple Store \u96f6\u552e\u5e97\u4e3e\u529e\u7684\u5b9e\u8df5\u8bfe\u7a0b\u91cc\u3002\u6765 Today at Apple \u770b\u770b\u4f60\u8eab\u8fb9\u90fd\u6709\u54ea\u4e9b\u7cbe\u5f69\u6d3b\u52a8\u3002", "engine": "bing", "template": "default.html", "parsed_url": ["https", "www.apple.com.cn", "/today/", "", "", ""], "engines": ["bing"], "positions": [1], "score": 1.0, "category": "general"},
.............
}
但是Open WebUI中依然显示获取到0条搜索结果。
继续查看Open WebUI搜索相关的源码(searxng插件,域名过滤列表函数),在域名过滤列表的函数里
def get_filtered_results(results, filter_list):
if not filter_list:
return results
filtered_results = []
for result in results:
url = result.get("url") or result.get("link", "")
if not validators.url(url):
continue
domain = urlparse(url).netloc
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
filtered_results.append(result)
return filtered_results
发现重要内容:
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
filtered_results.append(result)
这里的逻辑是保留并返回来自下面Open WebUI截图中 域名过滤列表 的结果,并不是常规意义上的去除掉过滤列表中的内容。而且当列表为空值时,这个过滤函数不执行,返回所有结果。
因此最终解决办法是删除过滤列表的内容,或者填写需要保留的内容,即可正常使用联网搜索功能。
附言:
- 如果 searXNG需要在境内使用bing,需要为bing项配置base_url项,因为境内bing会自动跳转cn网站导致搜索失败。
- Open WebUI中设置searXNG服务地址时填的是 searXNG相对于Open WebUI服务端的地址
- name: bing
engine: bing
shortcut: bi
disabled: false
base_url: "https://cn.bing.com/search"