pdphilip/opensearch
Composer 安装命令:
composer require pdphilip/opensearch
包简介
An OpenSearch implementation of Laravel's Eloquent ORM
README 文档
README

Laravel-OpenSearch
OpenSearch is a distributed, community-driven, Apache 2.0-licensed, 100% open-source search and analytics suite used for a broad set of use cases like real-time application monitoring, log analytics, and website search.
An OpenSearch implementation of Laravel's Eloquent ORM
The Power of OpenSearch with Laravel's Eloquent
This package extends Laravel's Eloquent model and query builder with seamless integration of OpenSearch functionalities. Designed to feel native to Laravel, this package enables you to work with Eloquent models while leveraging the powerful search and analytics capabilities of OpenSearch.
The Eloquent you already know:
UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
UserLog::create([
'user_id' => '2936adb0-b10d-11ed-8e03-0b234bda3e12',
'ip' => '62.182.98.146',
'location' => [40.7185,-74.0025],
'country_code' => 'US',
'status' => 1,
]);
UserLog::where('status', 1)->update(['status' => 4]);
UserLog::where('status', 4)->orderByDesc('created_at')->paginate(50);
UserProfile::whereIn('country_code',['US','CA'])
->orderByDesc('last_login')->take(10)->get();
UserProfile::where('state','unsubscribed')
->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
opensearch with Eloquent:
UserProfile::searchTerm('Laravel')->orSearchTerm('opensearch')->get();
UserProfile::searchPhrasePrefix('loves espressos and t')->highlight()->get();
UserProfile::whereMatch('bio', 'PHP')->get();
UserLog::whereGeoDistance('location', '10km', [40.7185,-74.0025])->get();
UserProfile::whereFuzzy('description', 'qick brwn fx')->get();
Built in Relationships (even to SQL models):
UserLog::where('status', 1)->orderByDesc('created_at')->with('user')->get();
Read the Documentation
Installation
Laravel 10.x, 11.x & 12.x (main):
composer require pdphilip/opensearch
| Laravel Version | Command | Maintained |
|---|---|---|
| Laravel 10/11/12 | composer require pdphilip/opensearch:~3 | ✅ |
| Laravel 10/11 (v2) | composer require pdphilip/opensearch:~2 | ❌ EOL |
| Laravel 8 & 9 | composer require pdphilip/opensearch:~1 | ❌ EOL |
Configuration
- Set up your
.envwith the following OpenSearch settings:
OS_HOSTS="http://opensearch:9200"
OS_USERNAME=
OS_PASSWORD=
OS_INDEX_PREFIX=my_app_
# prefix will be added to all indexes created by the package with an underscore
# ex: my_app_user_logs for UserLog.php model
# AWS SigV4 Config:
OS_SIG_V4_PROVIDER=
OS_SIG_V4_REGION=
OS_SIG_V4_SERVICE=
# Cert Config:
OS_SSL_CERT=
OS_SSL_CERT_PASSWORD=
OS_SSL_KEY=
OS_SSL_KEY_PASSWORD=
# Optional Settings:
OS_OPT_VERIFY_SSL=true
OS_OPT_RETRIES=
OS_OPT_SNIFF_ON_START=
OS_OPT_PORT_HOST_HEADERS=
OS_OPT_ID_SORTABLE=false
OS_OPT_META_HEADERS=true
OS_OPT_BYPASS_MAP_VALIDATION=false
OS_OPT_DEFAULT_LIMIT=1000
For multiple nodes, pass in as comma-separated:
OS_HOSTS="http://opensearch-node1:9200,http://opensearch-node2:9200,http://opensearch-node3:9200"
- In
config/database.php, add the OpensSearch connection:
'opensearch' => [
'driver' => 'opensearch',
'hosts' => explode(',', env('OS_HOSTS', 'http://localhost:9200')),
'basic_auth' => [
'username' => env('OS_USERNAME', ''),
'password' => env('OS_PASSWORD', ''),
],
'sig_v4' => [
'provider' => env('OS_SIG_V4_PROVIDER'),
'region' => env('OS_SIG_V4_REGION'),
'service' => env('OS_SIG_V4_SERVICE'),
],
'ssl' => [
'cert' => env('OS_SSL_CERT', ''),
'cert_password' => env('OS_SSL_CERT_PASSWORD', ''),
'key' => env('OS_SSL_KEY', ''),
'key_password' => env('OS_SSL_KEY_PASSWORD', ''),
],
'index_prefix' => env('OS_INDEX_PREFIX', false),
'options' => [
'bypass_map_validation' => env('OS_OPT_BYPASS_MAP_VALIDATION', false),
'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
'retires' => env('OS_OPT_RETRIES',null),
'sniff_on_start' => env('OS_OPT_SNIFF_ON_START',false),
'logging' => env('OS_OPT_LOGGING', false),
'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS',false),
'default_limit' => env('OS_OPT_DEFAULT_LIMIT', 1000),
'allow_id_sort' => env('OS_OPT_ID_SORTABLE', false),
],
],
3. If packages are not autoloaded, add the service provider:
For Laravel 10 and below:
//config/app.php
'providers' => [
...
...
PDPhilip\OpenSearch\OpenSearchServiceProvider::class,
...
For Laravel 11:
//bootstrap/providers.php
<?php
return [
App\Providers\AppServiceProvider::class,
PDPhilip\OpenSearch\OpenSearchServiceProvider::class,
];
Now, you're all set to use OpenSearch with Laravel as if it were native to the framework.
Documentation Links
Getting Started
Eloquent
- The Base Model
- Saving Models
- Deleting Models
- Querying Models
- Eloquent Queries
- OS Eloquent Queries
- Cross Fields Search Queries
- Aggregation Queries
- Distinct and GroupBy Queries
- Nested Queries
- Ordering and Pagination
- Chunking
- Dynamic Indices
Relationships
Migrations: Schema/Index
Misc
Credits
License
The MIT License (MIT). Please see License File for more information.
pdphilip/opensearch 适用场景与选型建议
pdphilip/opensearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 353.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「model」 「laravel」 「opensearch」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pdphilip/opensearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pdphilip/opensearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pdphilip/opensearch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
A PSR-7 compatible library for making CRUD API endpoints
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 353.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-28