Scout Elasticsearch Driver 使用教程
1. 项目介绍
Scout Elasticsearch Driver 是一个为 Laravel Scout 提供的 Elasticsearch 驱动扩展包。它允许你在 Laravel 应用中使用 Elasticsearch 进行高级搜索和数据过滤。该包提供了丰富的功能,包括索引配置、搜索规则、零停机迁移等,使得在 Laravel 项目中集成 Elasticsearch 变得更加简单和高效。
2. 项目快速启动
2.1 安装
首先,使用 Composer 安装 Scout Elasticsearch Driver:
composer require babenkoivan/scout-elasticsearch-driver
2.2 配置
安装完成后,需要发布 Scout 和 Scout Elasticsearch Driver 的配置文件:
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
php artisan vendor:publish --provider="ScoutElastic\ScoutElasticServiceProvider"
然后,在 config/scout.php 文件中设置驱动为 elastic:
'driver' => env('SCOUT_DRIVER', 'elastic'),
2.3 创建索引配置器
使用以下命令创建一个新的索引配置器:
php artisan make:index-configurator MyIndexConfigurator
在生成的 MyIndexConfigurator.php 文件中,你可以配置索引名称和设置:
namespace App;
use ScoutElastic\IndexConfigurator;
class MyIndexConfigurator extends IndexConfigurator
{
protected $name = 'my_index';
protected $settings = [
'analysis' => [
'analyzer' => [
'es_std' => [
'type' => 'standard',
'stopwords' => '_spanish_',
],
],
],
];
}
2.4 创建可搜索模型
使用以下命令创建一个新的可搜索模型:
php artisan make:searchable-model MyModel --index-configurator=MyIndexConfigurator
在生成的 MyModel.php 文件中,配置模型的索引配置器和映射:
namespace App;
use ScoutElastic\Searchable;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
use Searchable;
protected $indexConfigurator = MyIndexConfigurator::class;
protected $searchRules = [];
protected $mapping = [
'properties' => [
'title' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
],
],
],
],
];
}
2.5 创建和更新索引
创建索引:
php artisan elastic:create-index "App\MyIndexConfigurator"
更新模型映射:
php artisan elastic:update-mapping "App\MyModel"
2.6 基本搜索
现在你可以使用 Elasticsearch 进行搜索了:
$results = App\MyModel::search('phone')
->select(['title', 'price'])
->where('color', 'red')
->orderBy('price', 'asc')
->collapse('brand')
->from(0)
->take(10)
->get();
3. 应用案例和最佳实践
3.1 高级搜索
Scout Elasticsearch Driver 支持多种高级搜索功能,如布尔查询、地理距离过滤、正则表达式过滤等。以下是一个使用正则表达式过滤的示例:
$results = App\MyModel::search('*')
->whereRegexp('name.raw', 'A.+')
->get();
3.2 零停机迁移
在需要更改索引映射时,可以使用零停机迁移功能。首先,确保你的索引配置器使用了 ScoutElastic\Migratable 特性:
namespace App;
use ScoutElastic\IndexConfigurator;
use ScoutElastic\Migratable;
class MyIndexConfigurator extends IndexConfigurator
{
use Migratable;
protected $name = 'my_index';
}
然后,运行迁移命令:
php artisan elastic:migrate-model "App\MyModel" my_index_v2
4. 典型生态项目
4.1 Elastic Scout Driver
Elastic Scout Driver 是一个通用的 Elasticsearch 驱动,适用于需要简单搜索功能的 Laravel 应用。
4.2 Elastic Scout Driver Plus
Elastic Scout Driver Plus 是 Elastic Scout Driver 的扩展,提供了更多高级功能,如布尔查询、高亮显示等。
4.3 Elastic Migrations
Elastic Migrations 是一个用于管理 Elasticsearch 索引模式的工具,类似于 Laravel 的数据库迁移功能。
通过这些生态项目,你可以构建一个完整的 Elasticsearch 搜索解决方案,满足各种复杂搜索需求。
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00
PaddleOCR-VL-1.5PaddleOCR-VL-1.5 是 PaddleOCR-VL 的新一代进阶模型,在 OmniDocBench v1.5 上实现了 94.5% 的全新 state-of-the-art 准确率。 为了严格评估模型在真实物理畸变下的鲁棒性——包括扫描伪影、倾斜、扭曲、屏幕拍摄和光照变化——我们提出了 Real5-OmniDocBench 基准测试集。实验结果表明,该增强模型在新构建的基准测试集上达到了 SOTA 性能。此外,我们通过整合印章识别和文本检测识别(text spotting)任务扩展了模型的能力,同时保持 0.9B 的超紧凑 VLM 规模,具备高效率特性。Python00
xw-cli实现国产算力大模型零门槛部署,一键跑通 Qwen、GLM-4.7、Minimax-2.1、DeepSeek-OCR 等模型Go06
yuanrongopenYuanrong runtime:openYuanrong 多语言运行时提供函数分布式编程,支持 Python、Java、C++ 语言,实现类单机编程高性能分布式运行。Go051
pc-uishopTNT开源商城系统使用java语言开发,基于SpringBoot架构体系构建的一套b2b2c商城,商城是满足集平台自营和多商户入驻于一体的多商户运营服务系统。包含PC 端、手机端(H5\APP\小程序),系统架构以及实现案例中应满足和未来可能出现的业务系统进行对接。Vue00
ebook-to-mindmapepub、pdf 拆书 AI 总结TSX01