mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Enforce a limit for search results when searching through api
This commit is contained in:
parent
d7b5944c5f
commit
546c925224
@ -11,6 +11,7 @@ and this project adheres to
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
<!-- write down unreleased development here -->
|
<!-- write down unreleased development here -->
|
||||||
|
* [search] enforce limit of results for fetching rsults by search api https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/576
|
||||||
* [activity] Fix delete button for document (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/554)
|
* [activity] Fix delete button for document (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/554)
|
||||||
* [activity] Add return path the document generation (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/553)
|
* [activity] Add return path the document generation (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/553)
|
||||||
* [person] add person ressource to person docgen normaliser (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/517)
|
* [person] add person ressource to person docgen normaliser (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/517)
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Search;
|
namespace Chill\MainBundle\Search;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Pagination\Paginator;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
@ -102,9 +103,9 @@ class SearchApi
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildUnionQuery(array $queries, $types, $parameters)
|
private function buildUnionQuery(array $queries, $types, $parameters, Paginator $paginator)
|
||||||
{
|
{
|
||||||
$query = '{unions} ORDER BY pertinence DESC';
|
$query = '{unions} ORDER BY pertinence DESC LIMIT ? OFFSET ?';
|
||||||
$unions = [];
|
$unions = [];
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
|
|
||||||
@ -113,6 +114,10 @@ class SearchApi
|
|||||||
$parameters = array_merge($parameters, $q->buildParameters());
|
$parameters = array_merge($parameters, $q->buildParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add pagination limit
|
||||||
|
$parameters[] = $paginator->getItemsPerPage();
|
||||||
|
$parameters[] = $paginator->getCurrentPageFirstItemNumber();
|
||||||
|
|
||||||
$union = implode(' UNION ', $unions);
|
$union = implode(' UNION ', $unions);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -132,9 +137,9 @@ class SearchApi
|
|||||||
return (int) $countNq->getSingleScalarResult();
|
return (int) $countNq->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fetchRawResult($queries, $types, $parameters, $paginator): array
|
private function fetchRawResult($queries, $types, $parameters, Paginator $paginator): array
|
||||||
{
|
{
|
||||||
[$union, $parameters] = $this->buildUnionQuery($queries, $types, $parameters);
|
[$union, $parameters] = $this->buildUnionQuery($queries, $types, $parameters, $paginator);
|
||||||
$rsm = new ResultSetMappingBuilder($this->em);
|
$rsm = new ResultSetMappingBuilder($this->em);
|
||||||
$rsm->addScalarResult('key', 'key', Types::STRING)
|
$rsm->addScalarResult('key', 'key', Types::STRING)
|
||||||
->addScalarResult('metadata', 'metadata', Types::JSON)
|
->addScalarResult('metadata', 'metadata', Types::JSON)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user