Merge pull request #55434 from nextcloud/fix/unfied-search-pagination-limit

fix(unified-search): Remove hard-coded search result limit
master
F. E Noel Nfebe 18 hours ago committed by GitHub
commit a9d925b873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      core/AppInfo/ConfigLexicon.php
  2. 9
      core/Controller/UnifiedSearchController.php
  3. 2
      core/openapi-full.json
  4. 2
      core/openapi.json
  5. 2
      openapi.json

@ -34,6 +34,7 @@ class ConfigLexicon implements ILexicon {
public const USER_TIMEZONE = 'timezone'; public const USER_TIMEZONE = 'timezone';
public const UNIFIED_SEARCH_MIN_SEARCH_LENGTH = 'unified_search_min_search_length'; public const UNIFIED_SEARCH_MIN_SEARCH_LENGTH = 'unified_search_min_search_length';
public const UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST = 'unified_search_max_results_per_request';
public const LASTCRON_TIMESTAMP = 'lastcron'; public const LASTCRON_TIMESTAMP = 'lastcron';
@ -93,6 +94,7 @@ class ConfigLexicon implements ILexicon {
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM', lazy: true), new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM', lazy: true),
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'), 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'),
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'), 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'),
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'),
]; ];
} }

@ -9,6 +9,8 @@ declare(strict_types=1);
namespace OC\Core\Controller; namespace OC\Core\Controller;
use InvalidArgumentException; use InvalidArgumentException;
use OC\Core\AppInfo\Application;
use OC\Core\AppInfo\ConfigLexicon;
use OC\Core\ResponseDefinitions; use OC\Core\ResponseDefinitions;
use OC\Search\SearchComposer; use OC\Search\SearchComposer;
use OC\Search\SearchQuery; use OC\Search\SearchQuery;
@ -19,6 +21,7 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController; use OCP\AppFramework\OCSController;
use OCP\IAppConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
@ -39,6 +42,7 @@ class UnifiedSearchController extends OCSController {
private IRouter $router, private IRouter $router,
private IURLGenerator $urlGenerator, private IURLGenerator $urlGenerator,
private IL10N $l10n, private IL10N $l10n,
private IAppConfig $appConfig,
) { ) {
parent::__construct('core', $request); parent::__construct('core', $request);
} }
@ -72,7 +76,7 @@ class UnifiedSearchController extends OCSController {
* @param string $providerId ID of the provider * @param string $providerId ID of the provider
* @param string $term Term to search * @param string $term Term to search
* @param int|null $sortOrder Order of entries * @param int|null $sortOrder Order of entries
* @param int|null $limit Maximum amount of entries, limited to 25 * @param int|null $limit Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)
* @param int|string|null $cursor Offset for searching * @param int|string|null $cursor Offset for searching
* @param string $from The current user URL * @param string $from The current user URL
* *
@ -96,7 +100,8 @@ class UnifiedSearchController extends OCSController {
[$route, $routeParameters] = $this->getRouteInformation($from); [$route, $routeParameters] = $this->getRouteInformation($from);
$limit ??= SearchQuery::LIMIT_DEFAULT; $limit ??= SearchQuery::LIMIT_DEFAULT;
$limit = max(1, min($limit, 25)); $maxLimit = $this->appConfig->getValueInt(Application::APP_ID, ConfigLexicon::UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST);
$limit = max(1, min($limit, $maxLimit));
try { try {
$filters = $this->composer->buildFilterList($providerId, $this->request->getParams()); $filters = $this->composer->buildFilterList($providerId, $this->request->getParams());

@ -8511,7 +8511,7 @@
{ {
"name": "limit", "name": "limit",
"in": "query", "in": "query",
"description": "Maximum amount of entries, limited to 25", "description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
"schema": { "schema": {
"type": "integer", "type": "integer",
"format": "int64", "format": "int64",

@ -8511,7 +8511,7 @@
{ {
"name": "limit", "name": "limit",
"in": "query", "in": "query",
"description": "Maximum amount of entries, limited to 25", "description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
"schema": { "schema": {
"type": "integer", "type": "integer",
"format": "int64", "format": "int64",

@ -12024,7 +12024,7 @@
{ {
"name": "limit", "name": "limit",
"in": "query", "in": "query",
"description": "Maximum amount of entries, limited to 25", "description": "Maximum amount of entries (capped by configurable unified-search.max-results-per-request, default: 25)",
"schema": { "schema": {
"type": "integer", "type": "integer",
"format": "int64", "format": "int64",

Loading…
Cancel
Save