Skip to content

Commit

Permalink
Merge pull request #126 from ConductionNL/feature/DIMOC-234/pagination
Browse files Browse the repository at this point in the history
Enable pagination parameters
  • Loading branch information
rjzondervan authored Aug 8, 2024
2 parents bdcb133 + 0da6864 commit 1a2fdd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions lib/Service/ElasticSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ 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']);
}

unset($filters['.search'], $filters['.queries'], $filters['.catalogi']);

foreach ($filters as $name => $filter) {
Expand Down

0 comments on commit 1a2fdd5

Please sign in to comment.