violet88/silverstripe-elastica

为 Silverstripe 使用 Elastic Search 的模块

安装: 47

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:silverstripe-vendormodule

4.x-dev 2023-03-16 14:25 UTC

This package is auto-updated.

Last update: 2024-09-16 18:02:45 UTC


README

安装

运行以下命令来安装模块:

composer require violet88/silverstripe-elastica

配置

将以下内容添加到名为 dependencies.yml 的文件中:

SilverStripe\Core\Injector\Injector:
  Elastica\Client:
    constructor:
      - host: '`ELASTICA_HOST`'
        port: '`ELASTICA_PORT`'
        transport: '<TRANSPORT TYPE>'
        username: '<USERNAME>'
        password: '<PASSWORD>>'
        auth_type: '<AUTH TYPE>>'
  Violet88\Elastica\Tasks\ReindexTask:
    constructor:
      - '%$Violet88\Elastica\Services\ElasticaService'
  Violet88\Elastica\Extensions\Searchable:
    constructor:
      - '%$Violet88\Elastica\Services\ElasticaService'
  Violet88\Elastica\Services\ElasticaService:
    constructor:
      - '%$Elastica\Client'
      - '<INDEX NAME>'

并将以下内容添加到您的 _config.php 中:

if (!empty(Environment::getEnv('ELASTICASERVICE_INDEX'))) {
    Config::modify()->set('Injector', 'Violet88\Elastica\Services\ElasticaService', [
        'constructor' => [
            '%$Elastica\Client',
            Environment::getEnv('ELASTICASERVICE_INDEX'),
            isset($env['ElasticaService']['config']) ? $env['ElasticaService']['config'] : null
        ]
    ]);

    // register Searchables
    if (!empty(Environment::getEnv('ELASTICASERVICE_SEARCHABLE'))) {
        foreach (unserialize(Environment::getEnv('ELASTICASERVICE_SEARCHABLE')) as $class) {
            $class::add_extension('Violet88\Elastica\Extensions\Searchable');
        }
    }
}

将以下内容添加到您的环境变量中:

ELASTICASERVICE_INDEX='<NAME OF INDEX>'
ELASTICASERVICE_SEARCHABLE='<SERIALIZED ARRAY OF SEARCHABLE CLASSES>'
ELASTICA_HOST='<ELASTICSEARCH HOST'
ELASTICA_PORT='<ELASTICSEARCH PORT>'