aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-09-21 16:10:48 +0200
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-11-10 09:21:16 +0100
commitc753eefb217b041d9029da67f935211562079d16 (patch)
treee4171f68675716c4c2c1c4102df70a9f67dd8b32 /core/Controller
parent9de8e8e2244cfbed63f9c4d4b8abdd6092fa848c (diff)
downloadnextcloud-server-c753eefb217b041d9029da67f935211562079d16.tar.gz
nextcloud-server-c753eefb217b041d9029da67f935211562079d16.zip
feat(search): Allow multiple search terms in UnifiedController
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'core/Controller')
-rw-r--r--core/Controller/UnifiedSearchController.php35
1 files changed, 22 insertions, 13 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,