dama/solarium-bundle

此包已废弃,不再维护。作者建议使用nelmio/solarium-bundle包。

将Solarium库集成为Symfony包

安装量: 27,367

依赖者: 0

建议者: 0

安全: 0

星级: 1

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v1.3.0 2021-10-26 17:10 UTC

This package is auto-updated.

Last update: 2021-11-15 20:54:25 UTC


README

关于

DAMASolariumBundle提供了与Solarium solr客户端库的集成。

此Bundle部分基于NelmioSolariumBundle,并且完全兼容Symfony 5和Solarium 5.2。

安装

在composer.json中要求安装dama/solarium-bundle包,并更新您的依赖项。

$ composer require dama/solarium-bundle

将DAMASolariumBundle添加到您的AppKernel.php

public function registerBundles()
{
    $bundles = array(
        ...
        new \DAMA\SolariumBundle\DAMASolariumBundle(),
        ...
    );
    ...
}

基本配置

快速启动配置

dama_solarium: ~

提供具有默认选项(http://localhost:8983/solr)的Solarium客户端服务

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

在config.yml中配置您的端点

dama_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文档

多个客户端和端点

dama_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名称更改为您自己的名称,但如果您想要访问solarium.client服务,请不要忘记更改default_client选项。

dama_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');

您还可以在同一个客户端内拥有多个端点。

dama_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]

您还可以设置默认端点。

dama_solarium:
    endpoints:
        default:
            host: 192.168.1.2
        another:
            host: 192.168.1.3
    clients:
        default:
            endpoints: [default, another]
            default_endpoint: another

您还可以同时使用多个客户端和端点。

dama_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来访问您已配置的客户端,使用您在配置中使用的名称(例如上述示例)。

/** @var DAMA\SolariumBundle\ClientRegistryInterface $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或插件类

dama_solarium:
    clients:
        default:
            plugins:
                test_plugin_service:
                    plugin_service: plugin _service_id
                test_plugin_classname:
                    plugin_class: Some\Plugin\TestPlugin

覆盖Client类

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

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

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

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

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

HTTP请求超时

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

dama_solarium:
    clients:
        default:
            adapter_timeout: 10

许可证

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