nuwber/oponka
Composer 安装命令:
composer require nuwber/oponka
包简介
To be described
关键字:
README 文档
README
This package was inspired by the Plastic package, which provided a similar integration for Elasticsearch. Oponka builds upon the concepts established by Plastic, adapting them for the OpenSearch ecosystem. However, unlike Plastic, Oponka focuses solely on OpenSearch and does not include functionality for mapping indices to Eloquent models.
Oponka provides a seamless integration with OpenSearch for Laravel applications (version 10 and above). It simplifies the process of interacting with OpenSearch, allowing you to easily perform searches, index documents, and manage your OpenSearch data.
Features
Native OpenSearch Library: Utilizes the official OpenSearch PHP client for direct and efficient communication with your OpenSearch cluster.
OpenSearch DSL: Leverages the opensearch-dsl library to provide a more intuitive and expressive syntax for building complex search queries.
Easy Configuration: Simple configuration options allow you to quickly connect to your OpenSearch cluster and customize the package's behavior.
Laravel Integration: Integrates seamlessly with Laravel's service container and provides convenient helpers for accessing OpenSearch functionality within your application.
Installation
Install the package using Composer:
php composer require nuwber/oponka
Configuration
The OponkaServiceProvider will be used automatically as it is configured in the composer.json file.
If you need it in your project, you can use the following commands:
php artisan vendor:publish --provider="Nuwber\Oponka\OponkaServiceProvider"
Configure the Oponka connection:
Open the config/oponka.php file and change the connection settings as needed. Or do it with .env file.
Usage
The primary way to interact with Oponka is through the Oponka facade.
Getting the Client
You can access the underlying OpenSearch PHP client instance directly if needed:
use Nuwber\Oponka\Facades\Oponka; $client = Oponka::client(); // Now you can use the $client directly with the OpenSearch PHP client methods
Indexing Documents
To index a document, you can use the index method:
use Nuwber\Oponka\Facades\Oponka; $params = [ 'index' => 'my_index', 'id' => 'my_id', 'body' => ['testField' => 'abc'] ]; $response = Oponka::index($params); // $response contains the OpenSearch response array
Searching Documents
Oponka integrates with opensearch-dsl/opensearch-dsl. You can build your queries using its syntax.
use Nuwber\Oponka\Facades\Oponka; use OpenSearchDSL\Search; use OpenSearchDSL\Query\Compound\BoolQuery; use OpenSearchDSL\Query\TermLevel\TermQuery; use OpenSearchDSL\Query\FullText\MatchQuery; // Get the DSL Search object $search = Oponka::search(); // Or potentially a method to get a new Search object // Build a query $query = new BoolQuery(); $query->add(new MatchQuery('title', 'laravel')); $query->add(new TermQuery('status', 'published'), BoolQuery::FILTER); $search->addQuery($query); $search->setSource(['title', 'status', 'publish_date']); $search->setSize(10); $search->setFrom(0); // for pagination // Prepare the parameters for OpenSearch $params = [ 'index' => 'my_index', 'body' => $search->toArray(), ]; // Execute the search $results = Oponka::search($params); // Process results (assuming a Result object or similar is returned) // foreach ($results->getHits() as $hit) { // // Access hit data: $hit['_source'], $hit['_score'], etc. // } // $total = $results->getTotal();
Note: The exact methods for accessing the DSL builder and processing results might differ slightly. Please refer to the source code or tests for precise implementation.
Updating Documents
Use the update method:
use Nuwber\Oponka\Facades\Oponka; $params = [ 'index' => 'my_index', 'id' => 'my_id', 'body' => [ 'doc' => [ 'new_field' => 'xyz' ] ] ]; $response = Oponka::update($params);
Deleting Documents
Use the delete method:
use Nuwber\Oponka\Facades\Oponka; $params = [ 'index' => 'my_index', 'id' => 'my_id' ]; $response = Oponka::delete($params);
Direct Client Access
For operations not directly exposed or for more complex scenarios, you can always fall back to the native OpenSearch client:
use Nuwber\Oponka\Facades\Oponka; $client = Oponka::client(); $response = $client->cat()->indices(['index' => 'my_index', 'v' => true]);
nuwber/oponka 适用场景与选型建议
nuwber/oponka 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「opensearch」 「oponka」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nuwber/oponka 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nuwber/oponka 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nuwber/oponka 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alibaba Cloud OpenSearch SDK for PHP
OpenSearch driver for Laravel Scout
Alfabank REST API integration
Laravel, Lumen and Native php Elasticseach & Opensearch query builder to build complex queries using an elegant syntax ORM
Aliyun Openearch for Laravel 5
OpenSearch for PHP
统计信息
- 总下载量: 1.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-23