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

fix(search): Limit maximum number of search results #45317

Merged
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
7 changes: 5 additions & 2 deletions core/Controller/UnifiedSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getProviders(string $from = ''): DataResponse {
* @param string $providerId ID of the provider
* @param string $term Term to search
* @param int|null $sortOrder Order of entries
* @param int|null $limit Maximum amount of entries
* @param int|null $limit Maximum amount of entries, limited to 25
* @param int|string|null $cursor Offset for searching
* @param string $from The current user URL
*
Expand All @@ -113,6 +113,9 @@ public function search(
): DataResponse {
[$route, $routeParameters] = $this->getRouteInformation($from);

$limit ??= SearchQuery::LIMIT_DEFAULT;
$limit = max(1, min($limit, 25));

try {
$filters = $this->composer->buildFilterList($providerId, $this->request->getParams());
} catch (UnsupportedFilter|InvalidArgumentException $e) {
Expand All @@ -125,7 +128,7 @@ public function search(
new SearchQuery(
$filters,
$sortOrder ?? ISearchQuery::SORT_DATE_DESC,
$limit ?? SearchQuery::LIMIT_DEFAULT,
$limit,
$cursor,
$route,
$routeParameters
Expand Down
2 changes: 1 addition & 1 deletion core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5366,7 +5366,7 @@
{
"name": "limit",
"in": "query",
"description": "Maximum amount of entries",
"description": "Maximum amount of entries, limited to 25",
"schema": {
"type": "integer",
"format": "int64",
Expand Down
Loading