控制器:
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)
它解决了我试图使用半个单词搜索,但我不知道它需要是完整的单词才能被找到,谢谢