如何在Laravel5.2中进行加权查询?

ubof19bj  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(214)

我有一个搜索查询,我没有为此使用任何软件包。

  1. $title = stopWords($title);
  2. $query->where(function($q) use($title) {
  3. for ($i = 0; $i < count($title); $i++)
  4. {
  5. if ( count($title) > 1 && $i == 0 )
  6. continue;
  7. if ( count($title) > 1 )
  8. {
  9. $q->orWhere('title', 'like', '%' . $title[$i - 1] . ' ' . $title[$i] . '%');
  10. $q->orWhere('description', 'LIKE', '%' . $title[$i - 1] .' '.$title[$i]. '%');
  11. }
  12. else {
  13. $q->orWhere('title', 'like', '%' . $title[$i] . '%');
  14. $q->orWhere('description', 'LIKE', '%' . $title[$i] . '%');
  15. }
  16. }
  17. });

我想给与标题匹配的记录更多的权重,而不是描述,并按其权重排序结果。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题