1

私は、フィールド(検索可能にしたい)'name''description'と'tag_words'、およびブールフィールド'published'を持つモデル'Mix'を持っています。「published」フィールドが1に設定されている場合、ユーザーは複数の単語の検索用語を入力して、検索可能なフィールドのいずれかに表示される任意の単語の結果を取得できる必要があります。

これまでのところ、グーグルの助けを借りて、ここで読んでいます:

if ($this->request->is('post')) {
    $conditions = array();
    $search_terms = explode(' ', $this->request->data['Mix']['search']);
    foreach($search_terms as $search_term){
        $conditions[] = array('Mix.name Like' =>'%'.$search_term.'%');
        $conditions[] = array('Mix.description Like' =>'%'.$search_term.'%');
        $conditions[] = array('Mix.tag_words Like' =>'%'.$search_term.'%');
    }
    $searchResults = $this->paginate('Mix', array('conditions' => array('Mix.published'=>1, 'AND'=>array('OR' => $conditions))));
}

しかし、それはたくさんのエラーしか返さないので、私はそれが完全に間違っていると推測することができます。私は非常に混乱しています、正しい構文は何ですか?

4

1 に答える 1

1

あなたはインデックスを使用しませんAND、それはすでに暗示されています:-

$searchResults = $this->paginate('Mix', array('conditions' => array('Mix.published'=>1, 'OR' => $conditions)));
于 2013-03-15T14:53:56.667 に答える