violet88 / silverstripe-elastica
Module for Silverstripe to use Elastic Search
Installs: 48
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
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: 2025-02-16 18:46:16 UTC
README
Installation
Run the following command to install the module:
composer require violet88/silverstripe-elastica
Configuration
Add the following to a file called 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>'
And add the following to your _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'); } } }
Add the following to your environment variables:
ELASTICASERVICE_INDEX='<NAME OF INDEX>' ELASTICASERVICE_SEARCHABLE='<SERIALIZED ARRAY OF SEARCHABLE CLASSES>' ELASTICA_HOST='<ELASTICSEARCH HOST' ELASTICA_PORT='<ELASTICSEARCH PORT>'