btmoda / solarium-bundle
与 solarium solr 客户端集成。
4.0.1
2018-03-26 14:01 UTC
Requires
- php: >=5.5
- solarium/solarium: 4.0.0-beta.1
- symfony/framework-bundle: ^2.3 || ^3.0 || ^4.0
Requires (Dev)
- symfony/phpunit-bridge: ~3.3@dev
README
关于
NelmioSolariumBundle 提供了与 solarium solr 客户端的集成。
安装
在您的 composer.json 中需要 nelmio/solarium-bundle
包,并更新您的依赖关系。
$ composer require nelmio/solarium-bundle
将 NelmioSolariumBundle 添加到您的 AppKernel.php
public function registerBundles() { $bundles = array( ... new Nelmio\SolariumBundle\NelmioSolariumBundle(), ... ); ... }
基本配置
快速启动配置
nelmio_solarium: ~
提供一个具有默认选项的 Solarium_Client 服务(https://:8983/solr
)
$client = $this->get('solarium.client');
在 config.yml 中配置您的端点
nelmio_solarium: endpoints: default: scheme: http host: localhost port: 8983 path: /solr core: active timeout: 5 clients: default: endpoints: [default]
如果您只有一个端点,则不需要 client
部分
用法
$client = $this->get('solarium.client'); $select = $client->createSelect(); $select->setQuery('foo'); $results = $client->select($select);
更多信息请参阅 Solarium 文档。
多个客户端和端点
nelmio_solarium: endpoints: default: host: 192.168.1.2 another: host: 192.168.1.3 clients: default: endpoints: [default] another: endpoints: [another]
$defaultClient = $this->get('solarium.client'); $anotherClient = $this->get('solarium.client.another');
您也可以更改 default
名称为您自己的名称,但不要忘记更改 default_client
选项,如果您想访问 solarium.client
服务。
nelmio_solarium: default_client: firstOne endpoints: firstOne: host: 192.168.1.2 anotherOne: host: 192.168.1.3 clients: firstOne: endpoints: [firstOne] anotherOne: endpoints: [anotherOne]
$firstOneClient = $this->get('solarium.client'); //or $firstOneClient = $this->get('solarium.client.firstOne'); $anotherOneClient = $this->get('solarium.client.anotherOne');
从 Solarium 3.x 开始,您也可以在同一个客户端内部有多个端点。
nelmio_solarium: endpoints: default: host: 192.168.1.2 another: host: 192.168.1.3 # if you are using all the endpoints, the clients section is not necessary clients: default: endpoints: [default, another]
您也可以设置默认端点。
nelmio_solarium: endpoints: default: host: 192.168.1.2 another: host: 192.168.1.3 clients: default: endpoints: [default, another] default_endpoint: another
您还可以结合多个客户端和端点。
nelmio_solarium: endpoints: one: host: 192.168.1.2 two: host: 192.168.1.3 three: host: 192.168.1.4 clients: firstOne: endpoints: [one, two] default_endpoint: two secondOne: endpoints: [two, three] default_endpoint: three
客户端注册表
您还可以使用服务 solarium.client_registry
来访问您使用配置中使用的名称配置的客户端(例如上述示例)
$registry = $this->get('solarium.client_registry'); $firstOne = $registry->getClient('firstOne'); $secondOne = $registry->getClient('secondOne');
或者如果您已配置默认客户端
$registry = $this->get('solarium.client_registry'); $default = $registry->getClient();
插件
Solarium 与插件一起工作。如果您想使用自己的插件,您可以在包配置中注册插件,使用服务 ID 或插件类
nelmio_solarium: clients: default: plugins: test_plugin_service: plugin_service: plugin _service_id test_plugin_classname: plugin_class: Some\Plugin\TestPlugin
覆盖类
要更改适配器或客户端类,您可以设置 client_class 和 adapter_class 选项
nelmio_solarium: clients: default: client_class: Solarium\Core\Client adapter_class: Solarium\Core\Client\Adapter\Http
许可证
在 MIT 许可证下发布,请参阅 LICENSE。