【问题标题】:How to get data by using full text indexing in laravel?如何在 laravel 中使用全文索引获取数据?
【发布时间】: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


【解决方案1】:

为什么你只使用 Laravel Scout。它正式提供,并且可以与 Agolia 或 TNTsearch 索引服务集成。使用后可以通过 SQLlite 或 Agolia 对其进行索引

【讨论】:

  • 因为algolia非常昂贵
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
  • 2021-05-31
相关资源
最近更新 更多