Skip to content

Commit

Permalink
perf(plugin): improve searXNG empty result handling and documentation (
Browse files Browse the repository at this point in the history
…#3507)

* perf(plugin): improve searXNG empty result handling and documentation

* 修改了文档和代码部分无搜索的结果的反馈
  • Loading branch information
Jiangween authored Jan 2, 2025
1 parent 2a5a795 commit 1ea1438
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docSite/content/zh-cn/docs/guide/plugins/searxng_plugin_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ default_doi_resolver: 'oadoi.org'
}
```

* 搜索结果为空时会返回友好提示:

```Bash
{
"result": "[]",
"error": {
"message": "No search results",
"code": 500
}
}
```

* 失败时通过 Promise.reject 可能返回错误信息:

```Bash
Expand Down
10 changes: 10 additions & 0 deletions packages/plugins/src/searchXNG/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};
Expand Down

0 comments on commit 1ea1438

Please sign in to comment.