Skip to content

Commit 649dbb3

Browse files
committed
feat(unified-search): Configurable search result entries
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent f30ba61 commit 649dbb3

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

core/AppInfo/ConfigLexicon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ConfigLexicon implements ILexicon {
3434
public const USER_TIMEZONE = 'timezone';
3535

3636
public const UNIFIED_SEARCH_MIN_SEARCH_LENGTH = 'unified_search_min_search_length';
37+
public const UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST = 'unified_search_max_results_per_request';
3738

3839
public const LASTCRON_TIMESTAMP = 'lastcron';
3940

@@ -93,6 +94,7 @@ public function getAppConfigs(): array {
9394
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM', lazy: true),
9495
new Entry(self::OCM_INVITE_ACCEPT_DIALOG, ValueType::STRING, '', 'route to local invite accept dialog', lazy: true, note: 'set as empty string to disable feature'),
9596
new Entry(self::UNIFIED_SEARCH_MIN_SEARCH_LENGTH, ValueType::INT, 1, 'Minimum search length to trigger the request', lazy: false, rename: 'unified-search.min-search-length'),
97+
new Entry(self::UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST, ValueType::INT, 25, 'Maximum results returned per search request', lazy: false, rename: 'unified-search.max-results-per-request'),
9698
];
9799
}
98100

core/Controller/UnifiedSearchController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace OC\Core\Controller;
1010

1111
use InvalidArgumentException;
12+
use OC\Core\AppInfo\Application;
13+
use OC\Core\AppInfo\ConfigLexicon;
1214
use OC\Core\ResponseDefinitions;
1315
use OC\Search\SearchComposer;
1416
use OC\Search\SearchQuery;
@@ -19,6 +21,7 @@
1921
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2022
use OCP\AppFramework\Http\DataResponse;
2123
use OCP\AppFramework\OCSController;
24+
use OCP\IAppConfig;
2225
use OCP\IL10N;
2326
use OCP\IRequest;
2427
use OCP\IURLGenerator;
@@ -39,6 +42,7 @@ public function __construct(
3942
private IRouter $router,
4043
private IURLGenerator $urlGenerator,
4144
private IL10N $l10n,
45+
private IAppConfig $appConfig,
4246
) {
4347
parent::__construct('core', $request);
4448
}
@@ -72,7 +76,7 @@ public function getProviders(string $from = ''): DataResponse {
7276
* @param string $providerId ID of the provider
7377
* @param string $term Term to search
7478
* @param int|null $sortOrder Order of entries
75-
* @param int|null $limit Maximum amount of entries
79+
* @param int|null $limit Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)
7680
* @param int|string|null $cursor Offset for searching
7781
* @param string $from The current user URL
7882
*
@@ -96,7 +100,8 @@ public function search(
96100
[$route, $routeParameters] = $this->getRouteInformation($from);
97101

98102
$limit ??= SearchQuery::LIMIT_DEFAULT;
99-
$limit = max(1, $limit);
103+
$maxLimit = $this->appConfig->getValueInt(Application::APP_ID, ConfigLexicon::UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST);
104+
$limit = max(1, min($limit, $maxLimit));
100105

101106
try {
102107
$filters = $this->composer->buildFilterList($providerId, $this->request->getParams());

core/openapi-full.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8511,7 +8511,7 @@
85118511
{
85128512
"name": "limit",
85138513
"in": "query",
8514-
"description": "Maximum amount of entries",
8514+
"description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
85158515
"schema": {
85168516
"type": "integer",
85178517
"format": "int64",

core/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8511,7 +8511,7 @@
85118511
{
85128512
"name": "limit",
85138513
"in": "query",
8514-
"description": "Maximum amount of entries",
8514+
"description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
85158515
"schema": {
85168516
"type": "integer",
85178517
"format": "int64",

openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12020,7 +12020,7 @@
1202012020
{
1202112021
"name": "limit",
1202212022
"in": "query",
12023-
"description": "Maximum amount of entries",
12023+
"description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
1202412024
"schema": {
1202512025
"type": "integer",
1202612026
"format": "int64",

0 commit comments

Comments
 (0)