Search 通过多个关键字进行高级Codeigniter搜索

Search 通过多个关键字进行高级Codeigniter搜索,search,codeigniter-3,Search,Codeigniter 3,我想用codeigniter在数据库中多行搜索一定数量的关键字 我的代码如下所示: $search = array('search goes here'); $keywords = explode(' ', $search); $this->db->like('nume', $search); $this->db->or_like('id', $search); $this->db->or_like('desc

我想用codeigniter在数据库中多行搜索一定数量的关键字

我的代码如下所示:

$search = array('search goes here');
$keywords = explode(' ', $search);

        $this->db->like('nume', $search);
        $this->db->or_like('id', $search);
        $this->db->or_like('description', $search);
        $this->db->or_like('code', $search);
        $query = $this->db->get('property');
        $config['total_rows'] = $query->num_rows();
        $this->pagination->initialize($config);

        $this->db->like('nume', $search);
        $this->db->or_like('id', $search);
        $this->db->or_like('description', $search);
        $this->db->or_like('code', $search);
        $this->db->limit($config['per_page'], $this->uri->segment(4));
        $this->db->order_by('added_date', 'DESC');
        $query = $this->db->get("property");
        $properties = $data['properties'] = $query->result();
我想要的是:

foreach($keywords as $keyword) {
//some code that will search the database by each keyword
}

若您想通过搜索参数中的所有单词获得查询结果,最好的方法是使用。特别注意和。我想在我的应用程序中像谷歌一样搜索。例如:如果我搜索“迈阿密2间房公寓”。我想看看迈阿密所有有两个房间的公寓,而不仅仅是那些在您的描述中有全文全文搜索的公寓。如果您允许访客键入自定义查询,则全文搜索是一个不错的解决方案。如果表中有大量行,则速度也会更快。在没有更多细节的情况下,我不确定什么样的模型更适合您,但您可以在最后一行
$this->db->或_like()
之后重复
$this->db->或_like('nume',$keyword)放置您的foreach循环$这->数据库->或类似('id',$关键字)//etc
。检查是否需要使用
$this->db->distinct()以避免重复结果。在尝试通过活动记录运行查询之前,最好先用纯SQL固定查询