1

我有一个模型“混合”,它具有字段(我希望可搜索)“名称”“描述”和“标签字”,以及一个布尔字段“已发布”。如果“已发布”字段设置为 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 回答