【发布时间】:2021-05-13 22:32:00
【问题描述】:
我正在使用这个 laravel 包进行搜索
https://github.com/nicolaslopezj/searchable
这个包使用类似的查询
"select `id`, `name` from (select `customers`.*, max((case when LOWER(`customers`.`name`) LIKE ? then 15 else 0 end) + (case when LOWER(`customers`.`name`) LIKE ? then 5 else 0 end) + (case when LOWER(`customers`.`name`) LIKE ? then 1 else 0 end) + (case when LOWER(`customers`.`id`) LIKE ? then 30 else 0 end) + (case when LOWER(`customers`.`id`) LIKE ? then 10 else 0 end) + (case when LOWER(`customers`.`id`) LIKE ? then 2 else 0 end)) as relevance from `customers` group by `customers`.`id` having relevance >= 1.50 order by `relevance` desc) as `customers` limit 10"
我已对正在搜索的列进行索引,但未实现索引
这就是我搜索的方式
Customer::select('id','name')->search($request->keyword, null, true)->limit(10)->get();
【问题讨论】:
-
包正在执行的那种查询可能无法使用索引。您可能希望使用 MySQL 支持的 full text search
-
我推荐使用Laravel Scout 对 Eloquent 模型进行全文搜索。该软件包一直保留到最新版本的 Laravel 并且具有适当的集成。
-
Laravel scount 在没有 algolia 的情况下可以正常工作吗?
标签: php mysql laravel indexing