diff --git a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md index 36e1d2c60694..6652d7ff1458 100644 --- a/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md +++ b/docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md @@ -160,6 +160,18 @@ default_doi_resolver: 'oadoi.org' } ``` +* 搜索结果为空时会返回友好提示: + +```Bash +{ + "result": "[]", + "error": { + "message": "No search results", + "code": 500 + } +} +``` + * 失败时通过 Promise.reject 可能返回错误信息: ```Bash diff --git a/packages/plugins/src/searchXNG/index.ts b/packages/plugins/src/searchXNG/index.ts index c325f64a1b7b..eebe87adc7f4 100644 --- a/packages/plugins/src/searchXNG/index.ts +++ b/packages/plugins/src/searchXNG/index.ts @@ -48,6 +48,16 @@ const main = async (props: Props, retry = 3): Response => { }); }); + if (results.length === 0) { + return { + result: JSON.stringify([]), + error: { + message: 'No search results', + code: 500 + } + }; + } + return { result: JSON.stringify(results.slice(0, 10)) };