nelmio / solarium-bundle

与solarium solr客户端的集成。

安装次数: 2,412,421

依赖项: 10

建议者: 2

安全性: 0

星标: 149

关注者: 12

分支: 62

开放问题: 0

类型:symfony-bundle

v5.1.0 2023-09-22 09:07 UTC

README

Latest Version Total Downloads

关于

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: ~

提供具有默认选项(http://localhost:8983/solr)的Solarium_Client服务。

    $client = $this->get('solarium.client');

在config.yml中配置您的端点

nelmio_solarium:
    endpoints:
        default:
            scheme: http
            host: localhost
            port: 8983
            path: /solr
            core: active
    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

重写客户端类

要更改客户端类,您可以设置客户端类选项。

nelmio_solarium:
    clients:
        default:
            client_class: Solarium\Core\Client

自定义客户端使用的HTTP适配器

如果您需要自定义客户端执行HTTP请求到Solr时使用的适配器,则可以使用adapter_service选项指定用作适配器的symfony服务的ID。

nelmio_solarium:
    clients:
        default:
            adapter_service: 'my.custom.adapter.service'

HTTP请求超时

如果您使用的是默认适配器(Curl)且未自定义adapter_service,则可以使用adapter_timeout选项自定义超时。Solarium默认使用5秒超时。

nelmio_solarium:
    clients:
        default:
            adapter_timeout: 10

负载均衡器插件

Solarium附带一个负载均衡器插件,可以通过客户端级别的load_balancer选项进行配置。

传递端点列表将分配等于1的权重,并随机选择每个请求的端点。

nelmio_solarium:
    endpoints:
        one:
            host: 192.168.1.2
        two:
            host: 192.168.1.3
        three:
            host: 192.168.1.4
    clients:
        default:
            load_balancer:
                enabled: true
                endpoints: [ one, two, three ] # will assign equal weights of 1

您还可以为端点分配不同的权重(整数> = 1),以对负载均衡有更精细的控制。还有选项可以自定义阻塞的查询类型以及用于这些查询的默认端点。

nelmio_solarium:
    endpoints:
        one:
            host: 192.168.1.2
        two:
            host: 192.168.1.3
        three:
            host: 192.168.1.4
    clients:
        default:
            default_endpoint: two # the default endpoint to use for blocked query types 
            load_balancer:
                enabled: true
                blocked_query_types: [ 'select', 'update' ] # default is [ 'update' ]
                endpoints: 
                    one: 1
                    two: 2 # this endpoint will be used twice as often as the other two       
                    three: 1

有关负载均衡器插件的更多信息,请参阅Solarium文档:https://github.com/solariumphp/solarium/blob/master/docs/plugins.md#loadbalancer-plugin

许可证

在MIT许可证下发布,请参阅LICENSE。