diff --git a/lib/Controller/CatalogiController.php b/lib/Controller/CatalogiController.php index f0217df7..855133fe 100644 --- a/lib/Controller/CatalogiController.php +++ b/lib/Controller/CatalogiController.php @@ -45,15 +45,15 @@ public function index(ObjectService $objectService, SearchService $searchService if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - $searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch); - $searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->catalogMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->catalogMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - $filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); try { $dbConfig = [ diff --git a/lib/Controller/DirectoryController.php b/lib/Controller/DirectoryController.php index 6d9c5dd3..77b383eb 100644 --- a/lib/Controller/DirectoryController.php +++ b/lib/Controller/DirectoryController.php @@ -97,15 +97,15 @@ public function index(ObjectService $objectService, SearchService $searchService if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - $searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch); - $searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->listingMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->listingMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - $filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); $dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation'); $dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey'); diff --git a/lib/Controller/MetaDataController.php b/lib/Controller/MetaDataController.php index b2f9cdf8..8b2c8268 100644 --- a/lib/Controller/MetaDataController.php +++ b/lib/Controller/MetaDataController.php @@ -53,15 +53,15 @@ public function index(ObjectService $objectService, SearchService $searchService if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - $searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch); - $searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' =>$this->metaDataMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' =>$this->metaDataMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - $filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); $dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation'); $dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey'); diff --git a/lib/Controller/OrganisationsController.php b/lib/Controller/OrganisationsController.php index 3a8d6cf6..04cbbaf8 100644 --- a/lib/Controller/OrganisationsController.php +++ b/lib/Controller/OrganisationsController.php @@ -5,6 +5,7 @@ use OCA\OpenCatalogi\Db\OrganisationMapper; use OCA\OpenCatalogi\Service\ObjectService; use OCP\AppFramework\Controller; +use OCA\OpenCatalogi\Service\SearchService; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\IAppConfig; @@ -44,47 +45,24 @@ public function page(): TemplateResponse * * @return JSONResponse */ - public function index(ObjectService $objectService): JSONResponse + public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { - $filters = $this->request->getParams(); - - $searchConditions = []; - $searchParams = []; $fieldsToSearch = ['title', 'description', 'summary']; - foreach ($filters as $key => $value) { - if ($key === '_search') { - // MongoDB - $searchRegex = ['$regex' => $value, '$options' => 'i']; - $filters['$or'] = []; - - // MySQL - $searchParams['search'] = '%' . strtolower($value) . '%'; - - foreach ($fieldsToSearch as $field) { - // MongoDB - $filters['$or'][] = [$field => $searchRegex]; - - // MySQL - $searchConditions[] = "LOWER($field) LIKE :search"; - } - } - - if (str_starts_with($key, '_')) { - unset($filters[$key]); - } - } - if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - // Unset mongodb filter - unset($filters['$or']); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->organisationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->organisationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - + + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); + try { $dbConfig = [ 'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'), diff --git a/lib/Controller/PublicationsController.php b/lib/Controller/PublicationsController.php index 2e4e0446..d0fe3c44 100644 --- a/lib/Controller/PublicationsController.php +++ b/lib/Controller/PublicationsController.php @@ -107,15 +107,15 @@ public function index(ObjectService $objectService, SearchService $searchService if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - $searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch); - $searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - $filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch); + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); $dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation'); $dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey'); diff --git a/lib/Controller/SearchController.php b/lib/Controller/SearchController.php index 7fc12b75..27732845 100644 --- a/lib/Controller/SearchController.php +++ b/lib/Controller/SearchController.php @@ -74,11 +74,11 @@ public function index(SearchService $searchService): JSONResponse if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - $searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch); - $searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch); - $filters = $searchService->unsetSpecialQueryParams($filters); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } //@TODO: find a better way to get query params. This fixes it for now. diff --git a/lib/Controller/ThemesController.php b/lib/Controller/ThemesController.php index 2508bdb3..308c92c6 100644 --- a/lib/Controller/ThemesController.php +++ b/lib/Controller/ThemesController.php @@ -4,6 +4,7 @@ use OCA\OpenCatalogi\Db\ThemeMapper; use OCA\OpenCatalogi\Service\ObjectService; +use OCA\OpenCatalogi\Service\SearchService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\JSONResponse; @@ -58,47 +59,24 @@ public function page(): TemplateResponse * * @return JSONResponse */ - public function index(ObjectService $objectService): JSONResponse + public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { - $filters = $this->request->getParams(); - - $searchConditions = []; - $searchParams = []; $fieldsToSearch = ['title', 'description', 'summary']; - foreach ($filters as $key => $value) { - if ($key === '_search') { - // MongoDB - $searchRegex = ['$regex' => $value, '$options' => 'i']; - $filters['$or'] = []; - - // MySQL - $searchParams['search'] = '%' . strtolower($value) . '%'; - - foreach ($fieldsToSearch as $field) { - // MongoDB - $filters['$or'][] = [$field => $searchRegex]; - - // MySQL - $searchConditions[] = "LOWER($field) LIKE :search"; - } - } - - if (str_starts_with($key, '_')) { - unset($filters[$key]); - } - } - if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' ) { - // Unset mongodb filter - unset($filters['$or']); + $searchParams = $searchService->createMySQLSearchParams(filters: $filters); + $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->themeMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]); + return new JSONResponse(['results' => $this->themeMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } - + + $filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch); + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); + try { $dbConfig = [ 'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'), @@ -160,7 +138,7 @@ public function show(string $id, ObjectService $objectService): JSONResponse */ public function create(ObjectService $objectService): JSONResponse { - + $data = $this->request->getParams(); foreach ($data as $key => $value) {