Laravel 查询生成器搜索(匹配)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38488926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:11:27  来源:igfitidea点击:

Laravel Query Builder Search (match against)

phpmysqllaravel

提问by Marc

I'm trying to write this query in Laravel

我正在尝试在 Laravel 中编写此查询

select *, MATCH(hobbies)AGAINST('soccer') from users where MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE) LIMIT 10 OFFSET 0;

I have looked in the documentation on query builder but didn't find anything on full-text search.

我查看了有关查询构建器的文档,但在全文搜索中没有找到任何内容。

Please help.

请帮忙。

Thank you in advance :)

先感谢您 :)

回答by Tang3

User::selectRaw("*, MATCH(hobbies)AGAINST('soccer')")
    ->whereRaw("MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE)")
    ->limit(10);

回答by Marc

Thanks to Samsquanch he pointed me in the right direction. Here is how I got it done.

感谢 Samsquanch,他为我指明了正确的方向。这是我如何完成的。

$my_query = "select *, MATCH (name) AGAINST (?) from users 
    where MATCH (hobbies) AGAINST (? IN BOOLEAN MODE) limit 10 OFFSET ?"

$hobbies = DB::select($my_query, array($search_term, $search_term, (($page-1)*10)));