I have the following search query for my CakePHP application:
$this->paginate = array( 'limit'=>5, 'order'=>'Note.datetime DESC', 'conditions' => array( 'Note.status'=>1, 'OR' => array( 'Note.title LIKE' => '%'. $q . '%', 'Note.content LIKE' => '%'. $q . '%' ) ) );
Which takes a parameter named $q to make both a request for both the header and the content.
So, for example, if I have the following:
Title: Lorem ipsum Content: Lorem ipsum dolare
Search for 'lorem'
This will be good. But if I search for 'lorem dolare' , he will not find it.
How to do it?
Note. I do not want to use any plugins, etc.
EDIT: If I use FULLTEXT, will this work?
$this->paginate = array( 'limit'=>5, 'order'=>'Note.datetime DESC', 'conditions' => array( 'Note.status'=>1, 'OR' => array( 'MATCH(Note.title) AGAINST('.$q.' IN BOOLEAN MODE)', 'MATCH(Note.content) AGAINST('.$q.' IN BOOLEAN MODE)' ) ) );
EDIT 2:
Getting this error while trying above:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dolor IN BOOLEAN MODE)) OR (MATCH(`Note`.`content`) AGAINST(lorem dolor IN BOOLE' at line 1 SQL Query: SELECT `Note`.`id`, `Note`.`title`, `Note`.`excerpt`, `Note`.`content`, `Note`.`datetime`, `Note`.`user_id`, `Note`.`slug`, `Note`.`status`, `Note`.`topic_id`, `User`.`id`, `User`.`email`, `User`.`firstname`, `User`.`lastname`, `User`.`password`, `User`.`status`, `Topic`.`id`, `Topic`.`title`, `Topic`.`slug` FROM `db52704_driz2013`.`notes` AS `Note` LEFT JOIN `db52704_driz2013`.`users` AS `User` ON (`Note`.`user_id` = `User`.`id`) LEFT JOIN `db52704_driz2013`.`topics` AS `Topic` ON (`Note`.`topic_id` = `Topic`.`id`) WHERE `Note`.`status` = 1 AND ((MATCH(`Note`.`title`) AGAINST(lorem dolor IN BOOLEAN MODE)) OR (MATCH(`Note`.`content`) AGAINST(lorem dolor IN BOOLEAN MODE))) ORDER BY `Note`.`datetime` DESC LIMIT 5