Avatar britg

all the web, gaming, and foodie stuff that’s fit to printf()

Paginating MySQL Fulltext Searches in CakePHP

  1.  
  2. # query comes from GET request parameter ‘q’
  3. $input = $this->params[‘url’][‘q’];
  4.  
  5. # sanitize the query
  6. uses(’sanitize’);
  7. $sanitizer = new Sanitize();
  8. $q = $sanitizer->clean($input);
  9.  
  10. # now the pagination options hack to perform a fulltext search
  11. # we are searching a table called ‘listings’ with a fulltext index on
  12. # `title` and `description`
  13. $options[‘conditions’] = array(
  14.    ‘1′ => "1 AND MATCH(Listing.title,Listing.description)
  15.          AGAINST(’$q’ IN BOOLEAN MODE)"
  16. );
  17.  
  18. $this->set(‘results’ => $this->paginate(‘Listing’, $options);
  19.  

 
close Reblog this comment
blog comments powered by Disqus

Passion Projects