chapdel / laravel-meilitools
用于Laravel Scout与MeiliSearch集成的额外工具
1.2.0
2023-03-24 21:08 UTC
Requires
- php: ^7.4|^8.0|^8.1|^8.2
- illuminate/validation: ^8.0|^9.0|^10.0
Suggests
- brick/varexporter: Improves readability of console output for index details
README
此包的目的是简化MeiliSearch索引的配置,因此可以通过Laravel Scout使用高级过滤和排序,而无需手动操作他们的API。
目录
兼容性
安装
使用Composer安装此包
$ composer require chapdel/laravel-meilitools
配置
使用Artisan命令发布配置
$ php artisan vendor:publish --provider="Dwarf\MeiliTools\MeiliToolsServiceProvider"
通过config/meilitools.php
更改配置。
使用
此包提供命令和辅助工具,简化配置MeiliSearch索引的使用。
模型设置
通过实现合约提供的方法来设置模型的索引设置。
use Dwarf\MeiliTools\Contracts\Indexes\MeiliSettings; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Laravel\Scout\Searchable; class Article extends Model implements MeiliSettings { use Searchable; use SoftDeletes; /** * {@inheritdoc} */ public function meiliSettings(): array { // When using soft deletes '__soft_deleted' will automatically be added to filterable attributes. return ['filterableAttributes' => ['status']]; } }
可以在此处找到所有可用的索引设置的完整列表这里。
命令
以下命令可用
meili:index:create
- 创建新的MeiliSearch索引
参数
index
: 索引名称
选项
--force
: 强制执行操作
meili:index:delete
- 删除MeiliSearch索引
参数
index
: 索引名称
meili:index:details
- 获取MeiliSearch索引的详细信息
参数
index
: 索引名称
meili:index:reset
- 重置MeiliSearch索引的设置
参数
index
: 索引名称
选项
--pretend
: 只显示对索引所做的更改
meili:index:view
- 获取MeiliSearch索引的基本信息
参数
index
: 索引名称
选项
--stats
: 是否包含索引统计信息
meili:indexes:list
- 列出所有MeiliSearch索引
选项
--stats
: 是否包含索引统计信息
meili:model:details
- 获取MeiliSearch模型索引的详细信息
参数
model
: 模型类
meili:model:reset
- 重置MeiliSearch模型索引的设置
参数
model
: 模型类
选项
--pretend
: 只显示对索引所做的更改
meili:model:synchronize
- 同步MeiliSearch模型索引的设置
参数
model
: 模型类
meili:model:view
- 获取MeiliSearch模型索引的基本信息
参数
model
: 模型类
选项
--stats
: 是否包含索引统计信息
选项
--pretend
: 只显示对索引所做的更改
meili:models:synchronize
- 同步实现MeiliSearch索引设置的模型
选项
--pretend
: 只显示对索引所做的更改--force
: 在生产环境中强制执行操作
示例
模型命令可以同时接受完整的类名和基本名称,后者将使用配置的路径完成。
$ php artisan meili:model:details App\\Models\\Article
$ php artisan meili:model:details Article
$ php artisan meili:model:reset App\\Models\\Article
$ php artisan meili:model:reset Article
$ php artisan meili:model:synchronize App\\Models\\Article
$ php artisan meili:model:synchronize Article
$ php artisan meili:model:view App\\Models\\Article
$ php artisan meili:model:view Article
测试
可以通过Composer或直接调用PHPUnit二进制文件来运行测试。
$ composer test
要运行带有代码覆盖率的测试,请确保phpdbg
存在并可执行。
$ composer test:coverage $ open tests/_reports/index.html
职业
Dwarf A/S是一家总部位于哥本哈根(丹麦)的数字代理商,成立于2000年1月1日。
我们一直在寻找新的才华,因此请查看我们的网站以获取职位空缺。
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。