mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
implementing pagination api on search, and creating a "preview" of results
The search controller return a subset of the 5 first results. If the user want to see more, the services implementing SearchInterface should add a link "see more", and make use of the Pagination API to paginate.
This commit is contained in:
@@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\MainBundle\Search\UnknowSearchDomainException;
|
||||
use Chill\MainBundle\Search\UnknowSearchNameException;
|
||||
use Chill\MainBundle\Search\ParsingException;
|
||||
use Chill\MainBundle\Search\SearchInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -55,11 +56,29 @@ class SearchController extends Controller
|
||||
|
||||
try {
|
||||
if ($name === NULL) {
|
||||
// no specific search selected. Rendering result in "preview" mode
|
||||
$results = $this->get('chill.main.search_provider')
|
||||
->getSearchResults($request->query->get('q'));
|
||||
->getSearchResults(
|
||||
$pattern,
|
||||
0,
|
||||
5,
|
||||
array(SearchInterface::SEARCH_PREVIEW => true)
|
||||
);
|
||||
} else {
|
||||
// we want search on a specific search provider. Display full results.
|
||||
|
||||
// create a paginator to get the startPage and stopPage
|
||||
/* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */
|
||||
$paginatorFactory = $this->get('chill_main.paginator_factory');
|
||||
|
||||
$results = [$this->get('chill.main.search_provider')
|
||||
->getResultByName($pattern, $name)];
|
||||
->getResultByName(
|
||||
$pattern,
|
||||
$name,
|
||||
$paginatorFactory->getCurrentPageFirstItemNumber(),
|
||||
$paginatorFactory->getCurrentItemPerPage(),
|
||||
array(SearchInterface::SEARCH_PREVIEW => false)
|
||||
)];
|
||||
}
|
||||
} catch (UnknowSearchDomainException $ex) {
|
||||
return $this->render('ChillMainBundle:Search:error.html.twig',
|
||||
|
Reference in New Issue
Block a user