thinkphp 多条件模糊搜索结果,按照最佳匹配度排序,使用LOCATE函数

 1 //获取筛选参数
 2 $params = Request()->only(['keywords','brand_id', 'cat_id']);
 3 
 4 $where = "brand_id = " . $params['brand_id']
 5 
 6 $where .= " or (goods_name like '%" . $params['keywords'] . "%' or goods_sn like '%" . $params['keywords'] . "%' or desc_title like '%" . $params['keywords'] . "%' or keywords like '%" . $params['keywords'] . "%'))";
 7 
 8 $field = 'goods_id,brand_id,goods_name,desc_title,keywords'; 
9
10 $field .=(',LOCATE("'.$params['keywords'].'",goods_name) as gIndex');//使用LOCATE函数
11
12 $goods_list = (new GoodsModel())->get_goods_lists($field, $where, $order);

 

//使用LOCATE函数,查询出来的结果 以搜索 keywords ='方轴' 排序

SELECT goods_name,desc_title,sort_order,LOCATE('方轴',goods_name) as gIndex FROM goods WHERE goods_name LIKE '%方轴%' OR desc_title LIKE '%方轴%' OR keywords LIKE '%方轴%' ORDER BY gIndex DESC

 

posted @ 2019-06-14 17:31  Mr、桔子  阅读(1357)  评论(0编辑  收藏  举报