Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading