violet88 / silverstripe-elastica
为 Silverstripe 使用 Elastic Search 的模块
4.x-dev
2023-03-16 14:25 UTC
Requires
- php: ^7.4 || ^8.0
- ruflin/elastica: ^7.2
- silverstripe/admin: ^1.0
- silverstripe/framework: ^4.0
- symbiote/silverstripe-gridfieldextensions: ^3.4
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3.0
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>'