Skip to content

Commit

Permalink
Add Ingest Pipeline support.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Mar 25, 2024
1 parent 363ea00 commit 54659b9
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/module-elasticsuite-core/Api/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,22 @@ public function deleteByQuery(array $params): array;
* @return array
*/
public function updateByQuery(array $params): array;

/**
* Run an putPipeline request.
*
* @param array $params Pipeline params.
*
* @return array
*/
public function putPipeline(array $params): array;

/**
* Run an getPipeline request.
*
* @param string $name Pipeline.
*
* @return array
*/
public function getPipeline(string $name): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCore\Api\Index\Ingest;

/**
* Pipeline Interface
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
*/
interface PipelineInterface
{
/**
* Get name
*
* @return string
*/
public function getName(): string;

/**
* Get description
*
* @return string
*/
public function getDescription(): string;

/**
* Get processors
*
* @return array
*/
public function getProcessors(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCore\Api\Index\Ingest;

use Smile\ElasticsuiteCore\Index\Ingest\Pipeline;

/**
* Pipeline Manager
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
*/
interface PipelineManagerInterface
{
/**
* Create ingest pipeline.
*
* @param string $name name pipeline
* @param string $description description pipeline
* @param array $processors processors pipeline
*/
public function create(string $name, string $description, array $processors): ?Pipeline;

/**
* Get Pipeline by name.
*
* @param string $name Pipeline name.
*/
public function get(string $name): ?Pipeline;

/**
* Create Pipeline by index identifier.
*
* @param string $identifier Index identifier
*/
public function createByIndexIdentifier(string $identifier): ?Pipeline;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Api\Index\Ingest;

/**
* Pipeline Processor
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
*/
interface PipelineProcessorInterface
{
/**
* Get Pipeline processors.
*
* @return array
*/
public function getProcessors(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Api\Index\Ingest;

/**
* Pipeline Processor Provider
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
*/
interface PipelineProcessorProviderInterface
{
/**
* Get Pipeline processors by index identifier.
*
* @param string $indexIdentifier Index Identifier
*
* @return \Smile\ElasticsuiteCore\Api\Index\Ingest\PipelineProcessorInterface[]
*/
public function getProcessors(string $indexIdentifier) : array;
}
16 changes: 16 additions & 0 deletions src/module-elasticsuite-core/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ public function updateByQuery(array $params): array
return $this->getEsClient()->updateByQuery($params);
}

/**
* {@inheritDoc}
*/
public function putPipeline(array $params): array
{
return $this->getEsClient()->ingest()->putPipeline($params);
}

/**
* {@inheritDoc}
*/
public function getPipeline(string $name): array
{
return $this->getEsClient()->ingest()->getPipeline(['id' => $name]);
}

/**
* @return \OpenSearch\Client
*/
Expand Down
5 changes: 4 additions & 1 deletion src/module-elasticsuite-core/Index/AsyncIndexOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Smile\ElasticsuiteCore\Api\Client\ClientConfigurationInterface;
use Smile\ElasticsuiteCore\Api\Index\AsyncIndexOperationInterface;
use Smile\ElasticsuiteCore\Api\Index\Ingest\PipelineManagerInterface;

/**
* Asynchronous Index Operations interface
Expand Down Expand Up @@ -47,18 +48,20 @@ class AsyncIndexOperation extends IndexOperation implements AsyncIndexOperationI
* @param \Smile\ElasticsuiteCore\Api\Client\ClientInterface $client ES client.
* @param \Smile\ElasticsuiteCore\Api\Client\ClientConfigurationInterface $clientConfiguration ES client configuration.
* @param \Smile\ElasticsuiteCore\Api\Index\IndexSettingsInterface $indexSettings ES settings.
* @param PipelineManagerInterface $pipelineManager Ingest Pipeline Manager.
* @param \Psr\Log\LoggerInterface $logger Logger access.
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
\Smile\ElasticsuiteCore\Api\Client\ClientInterface $client,
\Smile\ElasticsuiteCore\Api\Client\ClientConfigurationInterface $clientConfiguration,
\Smile\ElasticsuiteCore\Api\Index\IndexSettingsInterface $indexSettings,
PipelineManagerInterface $pipelineManager,
\Psr\Log\LoggerInterface $logger
) {
$this->client = $client;
$this->parallelHandles = $clientConfiguration->getMaxParallelHandles();
parent::__construct($objectManager, $client, $indexSettings, $logger);
parent::__construct($objectManager, $client, $indexSettings, $pipelineManager, $logger);
}

/**
Expand Down
23 changes: 19 additions & 4 deletions src/module-elasticsuite-core/Index/IndexOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Smile\ElasticsuiteCore\Api\Index\Bulk\BulkResponseInterface;
use Smile\ElasticsuiteCore\Api\Index\IndexOperationInterface;
use Smile\ElasticsuiteCore\Api\Index\Ingest\PipelineManagerInterface;

/**
* Default implementation of operation on indices (\Smile\ElasticsuiteCore\Api\Index\IndexOperationInterface).
Expand Down Expand Up @@ -51,6 +52,11 @@ class IndexOperation implements IndexOperationInterface
*/
private $client;

/**
* @var \Smile\ElasticsuiteCore\Api\Index\Ingest\PipelineManagerInterface
*/
private $pipelineManager;

/**
* @var \Psr\Log\LoggerInterface
*/
Expand All @@ -59,21 +65,24 @@ class IndexOperation implements IndexOperationInterface
/**
* Instanciate the index operation manager.
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager Object manager.
* @param \Smile\ElasticsuiteCore\Api\Client\ClientInterface $client ES client.
* @param \Smile\ElasticsuiteCore\Api\Index\IndexSettingsInterface $indexSettings ES settings.
* @param \Psr\Log\LoggerInterface $logger Logger access.
* @param \Magento\Framework\ObjectManagerInterface $objectManager Object manager.
* @param \Smile\ElasticsuiteCore\Api\Client\ClientInterface $client ES client.
* @param \Smile\ElasticsuiteCore\Api\Index\IndexSettingsInterface $indexSettings ES settings.
* @param PipelineManagerInterface $pipelineManager Ingest Pipeline Manager.
* @param \Psr\Log\LoggerInterface $logger Logger access.
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
\Smile\ElasticsuiteCore\Api\Client\ClientInterface $client,
\Smile\ElasticsuiteCore\Api\Index\IndexSettingsInterface $indexSettings,
PipelineManagerInterface $pipelineManager,
\Psr\Log\LoggerInterface $logger
) {
$this->objectManager = $objectManager;
$this->client = $client;
$this->indexSettings = $indexSettings;
$this->indicesConfiguration = $indexSettings->getIndicesConfig();
$this->pipelineManager = $pipelineManager;
$this->logger = $logger;
}

Expand Down Expand Up @@ -138,6 +147,12 @@ public function createIndex($indexIdentifier, $store)
// @codingStandardsIgnoreEnd
$indexSettings['settings']['analysis'] = $this->indexSettings->getAnalysisSettings($store);

// Add (and create, if needed) default pipeline.
$pipeline = $this->pipelineManager->createByIndexIdentifier($indexIdentifier);
if ($pipeline !== null) {
$indexSettings['settings']['default_pipeline'] = $pipeline->getName();
}

$this->client->createIndex($index->getName(), $indexSettings);

$this->client->putMapping($index->getName(), $index->getMapping()->asArray());
Expand Down
68 changes: 68 additions & 0 deletions src/module-elasticsuite-core/Index/Ingest/Pipeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
* @copyright 2024 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Index\Ingest;

use Smile\ElasticsuiteCore\Api\Index\Ingest\PipelineInterface;

/**
* Ingest Pipeline Implementation
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Pierre Gauthier <pierre.gauthier@smile.fr>
*/
class Pipeline implements PipelineInterface
{
/**
* @param string $name Pipeline name
* @param string $description Pipeline description
* @param array $processors Pipeline processors
*/
public function __construct(
protected string $name,
protected string $description,
protected array $processors
) {
}

/**
* Get name
*
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* Get description
*
* @return string
*/
public function getDescription(): string
{
return $this->description;
}

/**
* Get processors
*
* @return array
*/
public function getProcessors(): array
{
return $this->processors;
}
}
Loading

0 comments on commit 54659b9

Please sign in to comment.