在Codeigniter中进行全文本搜索

Bah*_*eza 1 search full-text-search codeigniter sql-like

我有一个查询,可以使用like搜索关键字,但是我也想搜索全文,因此我将其更改为全文搜索查询,但是它不起作用。

工作正常的旧查询:

$data = $this->db
    ->select('content.title,content.id,content.category,content.body,path')
    ->from('content')   
    ->join('categories','content.category = categories.id')             
    ->like('content.title', $searchterm)
    ->like('content.body', $searchterm)
    ->order_by("content.id","DESC")
    ->get();
Run Code Online (Sandbox Code Playgroud)

这是我对全文搜索的新查询:

$data = $this->db
    ->select('content.title,content.id,content.category,content.body,path')
    ->from('content')   
    ->join('categories','content.category = categories.id')                 
    ->where('MATCH (content.body, content.title) AGAINST ("'. $searchterm .'")')
    ->order_by("content.id","DESC")
    ->get();
Run Code Online (Sandbox Code Playgroud)

Rez*_*eri 5

  1. 如果您使用的是MySQL 5.5或更低版本,请确保所有涉及的表都具有引擎MyISAM
  2. 确保您的列具有FULLTEXT INDEX
  3. where()需要3个参数,例如:

    $this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
    $this->db->get('table');  
    
    Run Code Online (Sandbox Code Playgroud)
  4. match()触发器中的多个列错误号:1191,因此将它们分开:

    ->where('MATCH (content.title) AGAINST ("'. $searchterm .'")')
    ->where('MATCH (content.body) AGAINST ("'. $searchterm .'")')
    
    Run Code Online (Sandbox Code Playgroud)