psagnataf / laravel-manticoresearch
在您的 Laravel 应用程序中使用官方 ManticoreSearch 客户端的简单方法
1.4.0
2020-09-24 17:50 UTC
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
- illuminate/contracts: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
- manticoresoftware/manticoresearch-php: ^1.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- limedeck/phpunit-detailed-printer: ^5.0|^6.0
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^9.0
- roave/security-advisories: dev-master
This package is not auto-updated.
Last update: 2024-09-23 04:22:15 UTC
README
Laravel ManticoreSearch 插件
在您的 Laravel 或 Lumen 应用程序中使用 官方 ManticoreSearch 客户端 的简单方法。
composer require psagnataf/laravel-manticoresearch
Laravel
该包的服务提供器将自动注册其服务提供器。
发布配置文件
php artisan vendor:publish --provider="ManticoreSearch\Laravel\ServiceProvider"
通过 .env 文件的方式配置替代方法
按照上述建议发布配置文件后,您可以通过向应用程序的 .env
文件中添加以下内容(使用适当的值)来配置 ManticoreSearch
MANTICORESEARCH_HOST=localhost MANTICORESEARCH_PORT=9200 MANTICORESEARCH_TRANSPORT=Http MANTICORESEARCH_USER= MANTICORESEARCH_PASS=
Lumen
如果您使用 Lumen,请在 bootstrap/app.php
中注册服务提供器和配置
$app->register(ManticoreSearch\Laravel\ServiceProvider::class); $app->configure('manticoresearch');
手动将配置文件复制到您的应用程序中。
使用方法
ManticoreSearch
门面只是 ManticoreSearch 客户端 的入口点,因此您之前可能使用过
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');
而不是上面的这些代码,您可以使用一行解决方案
$index = ManticoreSearch::index('movies');
这将在默认连接上运行命令。您可以在任何连接上运行命令(请参阅配置文件中的 defaultConnection
设置和 connections
数组)。
$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...
Client 类的方法
ManticoreSearch::connection('connectionName')->sql($params); ManticoreSearch::connection('connectionName')->replace($params); ManticoreSearch::connection('connectionName')->delete($params); // etc...
不使用门面的 Lumen 用户需要使用依赖注入或应用程序容器来获取 ManticoreSearch 索引对象
// using injection: public function handle(\ManticoreSearch\Laravel\Manager $manticoresearch) { $manticoresearch->describe(); } // using application container: $manticoreSearch = $this->app('manticoresearch');
当然,依赖注入和应用程序容器也适用于 Laravel 应用程序。