Skip to content

Commit

Permalink
Merge pull request #45317 from nextcloud/bugfix/noid/limit-maximum-nu…
Browse files Browse the repository at this point in the history
…mber-of-search-results

fix(search): Limit maximum number of search results
  • Loading branch information
nickvergessen committed May 16, 2024
2 parents bd6989d + 2bd54d3 commit ef1c32a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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 @@ -7006,7 +7006,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

0 comments on commit ef1c32a

Please sign in to comment.