diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/UnifiedSearchController.php | 35 | ||||
-rw-r--r-- | core/ResponseDefinitions.php | 4 | ||||
-rw-r--r-- | core/openapi.json | 29 |
3 files changed, 52 insertions, 16 deletions
diff --git a/core/Controller/UnifiedSearchController.php b/core/Controller/UnifiedSearchController.php index 9704850bb1f..87aa84e1d91 100644 --- a/core/Controller/UnifiedSearchController.php +++ b/core/Controller/UnifiedSearchController.php @@ -31,14 +31,15 @@ namespace OC\Core\Controller; use OC\Search\SearchComposer; use OC\Search\SearchQuery; use OCA\Core\ResponseDefinitions; -use OCP\AppFramework\OCSController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Route\IRouter; use OCP\Search\ISearchQuery; +use OC\Search\UnsupportedFilter; use Symfony\Component\Routing\Exception\ResourceNotFoundException; /** @@ -80,7 +81,10 @@ class UnifiedSearchController extends OCSController { * @NoAdminRequired * @NoCSRFRequired * - * Search + * Launch a search for a specific search provider. + * + * Additional filters are available for each provider. + * Send a request to /providers endpoint to list providers with their available filters. * * @param string $providerId ID of the provider * @param string $term Term to search @@ -89,28 +93,33 @@ class UnifiedSearchController extends OCSController { * @param int|string|null $cursor Offset for searching * @param string $from The current user URL * - * @return DataResponse<Http::STATUS_OK, CoreUnifiedSearchResult, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, null, array{}> + * @return DataResponse<Http::STATUS_OK, CoreUnifiedSearchResult, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, string, array{}> * * 200: Search entries returned * 400: Searching is not possible */ - public function search(string $providerId, - string $term = '', - ?int $sortOrder = null, - ?int $limit = null, - $cursor = null, - string $from = ''): DataResponse { - if (trim($term) === "") { - return new DataResponse(null, Http::STATUS_BAD_REQUEST); - } + public function search( + string $providerId, + // Unused parameter for OpenAPI spec generator + string $term = '', + ?int $sortOrder = null, + ?int $limit = null, + $cursor = null, + string $from = '', + ): DataResponse { [$route, $routeParameters] = $this->getRouteInformation($from); + try { + $filters = $this->composer->buildFilterList($providerId, $this->request->getParams()); + } catch (UnsupportedFilter $e) { + return new DataResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); + } return new DataResponse( $this->composer->search( $this->userSession->getUser(), $providerId, new SearchQuery( - $term, + $filters, $sortOrder ?? ISearchQuery::SORT_DATE_DESC, $limit ?? SearchQuery::LIMIT_DEFAULT, $cursor, diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index ca3f117051c..86eef1d2524 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -98,8 +98,12 @@ namespace OCA\Core; * * @psalm-type CoreUnifiedSearchProvider = array{ * id: string, + * appId: string, * name: string, + * icon: string, * order: int, + * triggers: string[], + * filters: array<string, string>, * } * * @psalm-type CoreUnifiedSearchResultEntry = array{ diff --git a/core/openapi.json b/core/openapi.json index 7cb48b58f0a..a63d9380db7 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -501,19 +501,41 @@ "type": "object", "required": [ "id", + "appId", "name", - "order" + "icon", + "order", + "triggers", + "filters" ], "properties": { "id": { "type": "string" }, + "appId": { + "type": "string" + }, "name": { "type": "string" }, + "icon": { + "type": "string" + }, "order": { "type": "integer", "format": "int64" + }, + "triggers": { + "type": "array", + "items": { + "type": "string" + } + }, + "filters": { + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, @@ -4000,7 +4022,8 @@ "/ocs/v2.php/search/providers/{providerId}/search": { "get": { "operationId": "unified_search-search", - "summary": "Search", + "summary": "Launch a search for a specific search provider.", + "description": "Additional filters are available for each provider. Send a request to /providers endpoint to list providers with their available filters.", "tags": [ "unified_search" ], @@ -4132,7 +4155,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "nullable": true + "type": "string" } } } |