Skip to content

0.1.8

Compare
Choose a tag to compare
@pionl pionl released this 04 Sep 12:37
· 7 commits to master since this release
a75db5a

🚀 Add ability to change available indices by implementing custom IndicesService (extend existing implementation or use IndicesServiceContract.

1. Edit lelastico.php config

'service' => MyOwnIndicesService::class,

2. Change the implementation

namespace App\ElasticSearch;

use App\Storage\ConfigStorageContract;
use App\Storage\ISConfigStorage;
use Illuminate\Contracts\Config\Repository;
use Lelastico\IndicesService;

class ISIndicesService extends IndicesService
{
    private ISConfigStorage $configStorage;

    public function __construct(Repository $configRepository, ISConfigStorage $configStorage)
    {
        parent::__construct($configRepository);
        $this->configStorage = $configStorage;
    }

    public function getAvailableIndices(): array
    {
        $groupedIndices = parent::getAvailableIndices();

        $baseIndices = $groupedIndices['base'];

        if ($this->configStorage->getDataSource() === ConfigStorageContract::IS2_DATA_STORE) {
            return array_merge($baseIndices, $groupedIndices['is2']);
        }

        return $baseIndices;
    }
}