Ich habe folgende find Abfrage für meine CakePHP App:CakePHP finden query% mit wie%
$this->paginate = array(
'limit'=>5,
'order'=>'Note.datetime DESC',
'conditions' => array(
'Note.status'=>1,
'OR' => array(
'Note.title LIKE' => '%'. $q . '%',
'Note.content LIKE' => '%'. $q . '%'
)
)
);
, die einen Parameter $q
zu tun, wie Abfrage sowohl Titel und Inhalt aufgerufen nimmt.
So zum Beispiel, wenn ich folgendes:
Title: Lorem ipsum
Content: Lorem ipsum dolare
und die Suche nach 'lorem'
Es es in Ordnung finden würde. Aber wenn ich nach 'lorem dolare'
suche, wird es es nicht finden.
Wie mache ich das?
Hinweis: Ich will keine Plugins verwenden usw.
EDIT: Wenn ich FULLTEXT- würde diese Arbeit?
$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:
Erhalten dieser Fehler die oben versuchen:
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
Versuchen Sie, die erste '%' –
@ Fred-II- Entfernen Immer noch nicht, es zu finden. – Cameron
Ich dachte gerade darüber nach, was Wayne unter "FULLTEXT" -Suche gepostet hat. Werfen Sie einen Blick auf diese Fragen und Antworten zu SO http://stackoverflow.com/q/17294924/1415724 kann helfen. –