Posted By

Pidarasiya on 09/30/16


Tagged

cakephp pagination Elasticsearch


Versions (?)

cakephp elastic-search pagination


 / Published in: PHP
 

URL: http://aerocoding.com/en/question/27/Using-cakephp-elastic-search-with-pagination

How do you use the elastic-search plugin with cake's native pagination?

  1. $products = $this->Product->find('all', array(
  2. 'fields' => array('id'),
  3. 'conditions' => array('title in' => explode(" ", $query))
  4. )->toArray();
  5.  
  6. $ids = array();
  7. foreach ($products as $product) {
  8. $ids[] = $product['id'];
  9. }
  10.  
  11. $this->paginate = [
  12. 'limit' => 10,
  13. 'conditions' => array(
  14. 'id IN' => array_unique($ids) //to eliminate duplicate ids
  15. ),
  16. ];
  17.  
  18. $products = $this->paginate('Products');
  19. $this->set('products', $products');

Report this snippet  

You need to login to post a comment.