From ec37e04fc0b920a19072edd9bc08480882bbab34 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Thu, 8 Aug 2024 15:17:45 +0200 Subject: [PATCH 1/2] Enable pagination parameters --- lib/Controller/SearchController.php | 20 +++++++++++++++++--- lib/Service/ElasticSearchService.php | 8 ++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/Controller/SearchController.php b/lib/Controller/SearchController.php index 48f3c4bd..7e4fcb90 100644 --- a/lib/Controller/SearchController.php +++ b/lib/Controller/SearchController.php @@ -95,14 +95,28 @@ public function index(SearchService $searchService): JSONResponse $fieldsToSearch = ['title', 'description', 'summary']; - if($this->config->hasKey($this->appName, 'mongoStorage') === false - || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' + if($this->config->hasKey($this->appName, 'elasticLocation') === false + || $this->config->getValueString($this->appName, 'elasticLocation') === '' ) { $searchParams = $searchService->createMySQLSearchParams(filters: $filters); $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); + + $limit = null; + $offset = null; + + if(isset($filters['_limit']) === true) { + $limit = $filters['_limit']; + } + + if(isset($filters['_page']) === true) { + $offset = ($limit * ($filters['_page'] - 1)); + } + $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); + + + return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: $limit, offset: $offset, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } //@TODO: find a better way to get query params. This fixes it for now. diff --git a/lib/Service/ElasticSearchService.php b/lib/Service/ElasticSearchService.php index 73bf354c..80354b57 100644 --- a/lib/Service/ElasticSearchService.php +++ b/lib/Service/ElasticSearchService.php @@ -124,6 +124,14 @@ public function parseFilters (array $filters): array ]; } + if(isset($filters['.limit']) === true) { + unset($filters['.limit']); + } + + if(isset($filters['.page']) === true) { + unset($filters['.page']); + } + unset($filters['.search'], $filters['.queries'], $filters['.catalogi']); foreach ($filters as $name => $filter) { From 0da686468572e3c133420e1417b9a8f59daaece5 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Thu, 8 Aug 2024 15:24:52 +0200 Subject: [PATCH 2/2] Add pagination --- lib/Service/ElasticSearchService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Service/ElasticSearchService.php b/lib/Service/ElasticSearchService.php index 80354b57..e6b93f10 100644 --- a/lib/Service/ElasticSearchService.php +++ b/lib/Service/ElasticSearchService.php @@ -125,10 +125,14 @@ public function parseFilters (array $filters): array } if(isset($filters['.limit']) === true) { + $body['size'] = $filters['.limit']; unset($filters['.limit']); } if(isset($filters['.page']) === true) { + if(isset($body['size']) === true) { + $body['from'] = $body['size'] * ($filters['.page'] - 1); + } unset($filters['.page']); }