omure/scout-advanced-meilisearch

Laravel Scout 扩展,允许使用 meilisearch 高级功能,同时提供了一个扩展的集合驱动程序,用于测试目的。

安装数: 3,868

依赖者: 0

建议者: 0

安全: 0

星星: 12

关注者: 1

分支: 5

开放问题: 1

类型:laravel-package

v0.5.2 2022-11-29 10:19 UTC

This package is auto-updated.

Last update: 2024-09-06 15:53:20 UTC


README

此包提供的内容

扩展的 scout 查询构建器

添加以下更改到基本查询构建器

  1. where('column', '<=', $value) - 扩展的 where,支持 3 个可选比较参数。也允许两个参数。
  2. where(Clusure $query) - where 可以将闭包作为第一个参数,以分组查询(同样适用于 orWhere
  3. whereBetween('column', [$value1, $value2])
  4. whereNotIn('column', [$value1, $value2, $value3])
  5. 所有 where 子句都有或变体:orWhereorWhereIn

两个 scout 驱动程序

驱动程序与新的 scout 构建器兼容。

  • meilisearch_advanced
  • collection_advanced

meilisearch_advanced

使用 meilisearch 的所有优势来比较结果,在索引数组中进行搜索。还修复了计算值总数的问题。(当前实现请求整个数据集,如果 scout 构建器使用了 ->query() 方法)

collection_advanced

驱动程序模拟 meilisearch 的工作方式,并完全依赖于集合。它仅应用于测试,因为所有可搜索模型的数据都在内存中。该驱动程序允许测试过滤、排序以及扩展的 scout 构建器功能。

考虑 meilisearch 特定问题

Meilisearch 需要更新可过滤、可排序和可搜索的属性索引,以便正确保存索引数据。此包提供 MeiliSearch 门面,该门面具有 updateIndexSettings 方法,可以自动处理。

如何使用?

  1. config/scout.php 中将 'driver' 设置为 meilisearch_advancedcollection_advanced
  2. Omure\ScoutAdvancedMeilisearch\Searchable 特性应用到模型上;
  3. 为了正确处理模型,将 Omure\ScoutAdvancedMeilisearch\Interfaces\MeiliSearchSearchableModel 接口实现到模型上
  4. 在模型的 toSearchableArray() 方法中描述索引参数,以进行搜索(与 Scout 的方式相同)
  5. 通过在模型上定义以下方法来指定可搜索、可过滤和可排序的属性
  • getSearchableAttributes() - 用于使用 search() 语句
  • getFilterableAttributes() - 用于使用 where(),包括 whereInwhereNotIn 等. 语句
  • getSortableAttributes() - 用于使用 orderBy() 语句
  • getTypoToleranceSettings() - 用于拼写容忍度 所有方法应返回一个字符串数组,这些字符串是 toSearchableArray() 中指定的参数的名称。

如果您更改了返回索引的 getSearchableAttributes()getFilterableAttributes()getSortableAttributes() 方法,则必须让 meilisearch 知道这些更改。为此,请使用门面: MeiliSearch::updateIndexSettings(new User());

该方法接收一个模型实例,以更新 meilisearch 服务器上的参数。

请注意,toSearchableArray() 不必与数据库列名相同的索引。您可以指定自己的搜索和过滤逻辑。在 Scout 构建器中使用指定的参数。