0

I'm trying to paginate with Symfony2, KnpPaginator and Solarium. There is no error returned nor pagination shown. {{ pagination.getTotalItemCount }} return "2", instead of much more. Actually, it count the number of argument in "array($client,$select)".

Any idea ?

From the controller :

           $my_query = 'manufacturer:'.$pays.' AND description:*inclus* AND terms:[* TO *]';
            // Create new solarium instance
            $client = $this->get('solarium.client');
            $select = $client->createSelect();
            //$select->setRows(15);
            $select->setQuery($my_query);
            $select->addSort('price', $select::SORT_ASC);
            if (isset($start))
            {
                    $select->setStart($start);
            }
            $resultsolr = $client->select($select);
            $nb_result =  $resultsolr->getNumFound();

            // Nav facettes
            $query = $client->createSelect();
            $query->createFilterQuery('inclus')->setQuery('description:*inclus* AND terms:[* TO *]');
            $facetSet = $query->getFacetSet();
            $facetSet->createFacetField('pays')->setField('manufacturer')->setMincount(1);
            $resultset = $client->select($query);
            $facet = $resultset->getFacetSet()->getFacet('pays');

            //Pagination
            $paginator  = $this->get('knp_paginator');
            $pagination = $paginator->paginate(array($client,$select),  $this->get('request')->query->get('page', 1)/*page number*/,
    20/*limit per page*/);

            return $this->render('TravelTravelBundle:Default:sejours_par_pays.html.twig',
                            array('resultsolr' => $resultsolr,
                                    'pays' => $pays,
                                    'facet' => $facet,
                                    'nb_result' => $nb_result,
                                    'pagination' => $pagination));
    }

From the view :

<div class="count">
    {{ pagination.getTotalItemCount }}
</div>

edit : I've found the answer (in French) : http://inside.inclusive.fr/2013/09/knppaginatorbundle-et-solarium/

Matteo
  • 37,680
  • 11
  • 100
  • 115
Quentin
  • 631
  • 6
  • 16
  • Looks like it's working with :`$array_from_resultsolr = $resultsolr->getDocuments(); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($array_from_resultsolr, $this->get('request')->query->get('page', 1)/*page number*/,5/*limit per page*/); ` – Quentin Sep 09 '13 at 10:31
  • Even more about KnpPaginator and Solarium there : http://inside.inclusive.fr/2013/09/knppaginatorbundle-et-solarium/ – Quentin Sep 11 '13 at 15:34
  • very informative article, except you writing here in english and article in french and I don't understand it – waney Oct 19 '16 at 23:24
  • Above solution works but its not feasible. As every time it need to get all data from solr and pass to paginator. Yes solr is very good to provide data, But its not feasible to pass all solr data to paginator (to show only 10 or 20 records) even though page number change. – Kiran Nov 01 '17 at 06:44

0 Answers0