定制 nuwber/oponka 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 nuwber/oponka 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-23