Laravel MySQL匹配不会返回结果

时间:2015-07-13 14:41:46

标签: php mysql laravel match match-against

这是控制器:

public function getSearch()
{   
    $search = e(Input::get('name'));
    $search = preg_replace('#[^a-z A-Z 0-9 ? !]#i',' ', $search);
    $query = "MATCH (name,description) AGAINST ('".$search."' IN BOOLEAN MODE)";
    $accounts = Account::whereRaw($query)->paginate(10);
    if ($accounts->count())
    {
        return View::make('accounts.all')->with('accounts',$accounts);
    }
    else
    {
        $accounts = Account::paginate(10);
        Session::flash('fail', 'Sorry, the search term - '.$search.' did not match any records');
        return View::make('accounts.all')->with('accounts',$accounts);
    }
}

因此控制器执行else语句,但没有任何错误。

这是行查询:

SELECT * FROM `accounts`  WHERE MATCH(name,description) AGAINST('search word' IN BOOLEAN MODE)

1 个答案:

答案 0 :(得分:0)

它解决了我试图用一半的单词搜索,但我不知道它需要是完整的单词才能找到,谢谢