承接 webregul/laravel-manticoresearch 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webregul/laravel-manticoresearch

Composer 安装命令:

composer require webregul/laravel-manticoresearch

包简介

An easy way to use the official ManticoreSearch client in your Laravel applications

README 文档

README

Latest Stable Version Total Downloads Build Status Code Coverage Code Climate Scrutinizer Code Quality License

Laravel ManticoreSearch plugin

An easiest way to use the official ManticoreSearch client in your Laravel or Lumen applications.

Fork from evilfreelancer/laravel-manticoresearch with Laravel 10 support

composer require webregul/laravel-manticoresearch

Post install

Laravel

The package's service provider will automatically register its service provider.

Publish the configuration file:

php artisan vendor:publish --provider="ManticoreSearch\Laravel\ServiceProvider"

Alternative configuration method via .env file

After you publish the configuration file as suggested above, you may configure ManticoreSearch by adding the following to your application's .env file (with appropriate values):

MANTICORESEARCH_HOST=localhost
MANTICORESEARCH_PORT=9200
MANTICORESEARCH_TRANSPORT=Http
MANTICORESEARCH_USER=
MANTICORESEARCH_PASS=

All available environments variables

Name Default value Description
MANTICORESEARCH_CONNECTION default Name of default connection
MANTICORESEARCH_HOST localhost Address of host with Manticore server
MANTICORESEARCH_PORT 9308 Port number with REST server
MANTICORESEARCH_TRANSPORT Http Type of transport, can be: Http, Https, PhpHttp or your custom driver
MANTICORESEARCH_USER Username
MANTICORESEARCH_PASS Password
MANTICORESEARCH_TIMEOUT 5 Timeout between requests
MANTICORESEARCH_CONNECTION_TIMEOUT 1 Timeout before connection
MANTICORESEARCH_PROXY Url of HTTP proxy server
MANTICORESEARCH_PERSISTENT true Define whenever connection is persistent or not
MANTICORESEARCH_RETRIES 2 Amount of retries if connection is lost

Lumen

If you work with Lumen, please register the service provider and configuration in bootstrap/app.php:

// Enable shortname of facade
$app->withFacades(true, [
    'ManticoreSearch\Laravel\Facade' => 'Facade',
]);

// Register Config Files
$app->configure('manticoresearch');

// Register Service Providers
$app->register(ManticoreSearch\Laravel\ServiceProvider::class);

Manually copy the configuration file to your application.

How to use

The ManticoreSearch facade is just an entry point into the ManticoreSearch client, so previously you might have used:

require_once __DIR__ . '/vendor/autoload.php';

$config = ['host'=>'127.0.0.1', 'port'=>9308];
$client = new \Manticoresearch\Client($config);
$index  = new \Manticoresearch\Index($client);
$index->setName('movies'); 

Instead of these few lines above you can use single line solution:

$index = \ManticoreSearch::index('movies');

That will run the command on the default connection. You can run a command on any connection (see the defaultConnection setting and connections array in the configuration file).

$index   = \ManticoreSearch::connection('connectionName')->index($nameOfIndex);
$pq      = \ManticoreSearch::connection('connectionName')->pq();
$cluster = \ManticoreSearch::connection('connectionName')->cluster();
$indices = \ManticoreSearch::connection('connectionName')->indices();
$nodes   = \ManticoreSearch::connection('connectionName')->nodes();

// etc...

methods of the Client class:

\ManticoreSearch::connection('connectionName')->sql($params);
\ManticoreSearch::connection('connectionName')->replace($params);
\ManticoreSearch::connection('connectionName')->delete($params);

// etc...

Lumen users who aren't using facades will need to use dependency injection, or the application container in order to get the ManticoreSearch Index object:

// using injection:
public function handle(\ManticoreSearch\Laravel\Manager $manticoresearch)
{
    $manticoresearch->describe();
}

// using application container:
$manticoreSearch = $this->app('manticoresearch');

Of course, dependency injection and the application container work for Laravel applications as well.

Logging

Since the PHP client of the ManticoreSearch supports logging through PSR-compatible loggers, you can use them in the same way as presented in the official documentation.

For example, you want to use the Monolog logger.

composer require monolog/monolog

By default, you need to write something like this:

$logger = new \Monolog\Logger('name');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('/my/log.file', Logger::INFO));
$config = ['host' => '127.0.0.1', 'port' => 9306];
$client = new \Manticoresearch\Client($config, $logger);
$index  = new \Manticoresearch\Index($client);
$index->setName('movies');

But if you want to use the Monolog together with this library then you may simplify your code like this:

$logger = new \Monolog\Logger('name');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('/my/log.file', Logger::INFO));

$index = \ManticoreSearch::connection('connectionName', $logger)->index('movies');

Testing

Just install dev requirements composer install --dev, then execute following command from root of this library:

./vendor/bin/phpunit

Links

webregul/laravel-manticoresearch 适用场景与选型建议

webregul/laravel-manticoresearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 323 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webregul/laravel-manticoresearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webregul/laravel-manticoresearch 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 323
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-12