shufo/laravel-opensearch
Composer 安装命令:
composer require shufo/laravel-opensearch
包简介
An easy way to use the official PHP OpenSearch client in your Laravel applications.
README 文档
README
⚠️ This package is still in alpha. Don't use in production.
An easy way to use the official OpenSearch client in your Laravel applications.
This is the fork of laravel-elasticsearch.
Installation and Configuration
Add repository to your composer.json
"repositories": [ { "type": "vcs", "url": "https://github.com/shufo/opensearch-php" } ],
then
composer require shufo/laravel-opensearch
Laravel
The package's service provider will automatically register its service provider.
Publish the configuration file:
php artisan vendor:publish --provider="Shufo\LaravelOpenSearch\ServiceProvider"
To change host of opensearch, set OPENSEARCH_HOST environment variable to your opensearch hostname.
To edit config you can edit config/opensearch.php.
$ vim config/opensearch.php
Usage
With Facade:
// search >>> OpenSearch::search([ 'index' => 'example', 'body' => [ 'query' => [ 'match' => [ 'id' => '123' ] ] ] ]) => [ "took" => 1, "timed_out" => false, "_shards" => [ "total" => 1, "successful" => 1, "skipped" => 0, "failed" => 0, ], "hits" => [ "total" => [ "value" => 1, "relation" => "eq", ], "max_score" => 0.6931471, "hits" => [ [ "_index" => "example", "_type" => "_doc", "_id" => "1", "_score" => 0.6931471, "_source" => [ "id" => "123", "body" => "test", ], ], ], ], ] // create index OpenSearch::indices()->create([ 'index' => 'example', 'body' => [ 'mappings' => [ 'properties' => [ 'id' => [ 'type' => 'long', ], 'text' => [ 'type' => 'text', ] ] ] ], ]) // add document to index OpenSearch::index([ "id" => "123", "body" => [ "id" => "123", "text" => "foo", ], "index" => "example", ]); // delete index OpenSearch::indices()->delete(['index' => 'example']); // SQL (currently it's available only select operation) >>> OpenSearch::sql()->query(["query" => "select * from example", "fetch_size" => 1]) => [ "schema" => [ [ "name" => "body", "type" => "text", ], [ "name" => "id", "type" => "keyword", ], ], "cursor" => "d:eyJhIjp7fSwicyI6IkZHbHVZMngxWkdWZlkyOXVkR1Y0ZEY5MWRXbGtEWEYxWlhKNVFXNWtSbVYwWTJnQkZrTmZVamR0VEc1ZlUwSmxOM2h4U2w5bFRWQjRaMUVBQUFBQUFBQUFxaFpqUjFGckxVRm9YMUl6Vnpkc2NXaHlabkk1VFZGbiIsImMiOlt7Im5hbWUiOiJib2R5IiwidHlwZSI6InRleHQifSx7Im5hbWUiOiJpZCIsInR5cGUiOiJrZXl3b3JkIn1dLCJmIjoxLCJpIjoiZXhhbXBsZSIsImwiOjF9", "total" => 2, "datarows" => [ [ "test", "123", ], ], "size" => 1, "status" => 200, ]
With Opensearch Client Builder:
use OpenSearch\ClientBuilder; $data = [ 'body' => [ 'testField' => 'abc' ], 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id', ]; $client = ClientBuilder::create()->build(); $return = $client->index($data);
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
LICENSE
MIT
shufo/laravel-opensearch 适用场景与选型建议
shufo/laravel-opensearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.79k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「search」 「laravel」 「opensearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shufo/laravel-opensearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shufo/laravel-opensearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shufo/laravel-opensearch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Abstraction Layer to index and search entities
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Pimcore 10.x Website Indexer (powered by Zend Search Lucene)
统计信息
- 总下载量: 8.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-12