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:
2016-08-19 21:33:37 +02:00
parent 2732bb1553
commit d20404bc3c
4 changed files with 64 additions and 8 deletions

View File

@@ -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',