Merge branch 'features/api-search' into 'master'

Features/api search

See merge request Chill-Projet/chill-bundles!98
This commit is contained in:
2021-06-29 14:50:28 +00:00
12 changed files with 431 additions and 54 deletions

View File

@@ -36,6 +36,7 @@ use Chill\MainBundle\Search\SearchProvider;
use Symfony\Contracts\Translation\TranslatorInterface;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Search\SearchApi;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
/**
* Class SearchController
@@ -151,11 +152,14 @@ class SearchController extends AbstractController
{
//TODO this is an incomplete implementation
$query = $request->query->get('q', '');
$types = $request->query->get('type', []);
$results = $this->searchApi->getResults($query, 0, 150);
$paginator = $this->paginatorFactory->create(count($results));
if (count($types) === 0) {
throw new BadRequestException("The request must contains at "
." one type");
}
$collection = new Collection($results, $paginator);
$collection = $this->searchApi->getResults($query, $types, []);
return $this->json($collection);
}