我正在嘗試搜索多個單詞。我已經嘗試在我的數據庫模式中添加FULLTEXT。CodeIgniter ActiveRecord FULLTEXT多個詞搜索
這是我現在的代碼,只有一個單詞返回結果。
$term = $this->input->post('term');
$this->db->like('firstname', $term);
$this->db->or_like('lastname', $term);
$this->db->or_like('middlename', $term);
$query = $this->db->get('people');
$data['people'] = $query->result();
$this->load->view('people', $data);
搜索「John」或「Doe」或「Smith」這樣的單詞是有效的。
但是,當我嘗試搜索「John Doe」或「John Doe Smith」時,它不會返回任何結果。
如何通過使用CodeIgniter的活動記錄或「$ this-> get-> query」來實現多個單詞搜索。
如果你想使用全文索引,則必須使用'MATCH()'和'AGAINST()'MySql函數。 – DanMan