Skip to content

Commit

Permalink
PD-96 Add Opensearch Client. (#20)
Browse files Browse the repository at this point in the history
* PD-96 Add Opensearch Client.

* PD-96 Add doc

* PD-96 Code style.

* Apply php-cs-fixer changes

* PD-96 Code style.
  • Loading branch information
martineiber authored Feb 2, 2024
1 parent 9d7167a commit 59a2163
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 63 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": "~8.1.0 || ~8.2.0",
"pimcore/enterprise-subscription-tools": "^1.3",
"pimcore/pimcore": "^11.1",
"opensearch-project/opensearch-php": "^2.2.0",
"pimcore/opensearch-client": "^1.x-dev",
"doctrine/orm": "^2.17.2",
"symfony/scheduler": "^6.4",
"symfony/messenger": "^6.4"
Expand Down
12 changes: 3 additions & 9 deletions config/services/search/open-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ services:
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchService
arguments:
$openSearchClient: '@generic-data-index-bundle.opensearch-client'
$openSearchClient: '@pimcore.open_search_client.data_index'

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\PathServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\PathService
arguments:
$openSearchClient: '@generic-data-index-bundle.opensearch-client'

Pimcore\Bundle\GenericDataIndexBundle\DependencyInjection\Factory\OpenSearchClientFactory: ~
$openSearchClient: '@pimcore.open_search_client.data_index'

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\Search\Tree\AssetTreeServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\Search\Tree\AssetTreeService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\Search\Pagination\PaginationInfoServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\Search\Pagination\PaginationInfoService

generic-data-index-bundle.opensearch-client:
class: OpenSearch\Client
factory: ['@Pimcore\Bundle\GenericDataIndexBundle\DependencyInjection\Factory\OpenSearchClientFactory', 'createOpenSearchClient']
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\Search\Pagination\PaginationInfoService
13 changes: 13 additions & 0 deletions doc/02_Configuration/04_Opensearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Open Search setup

Following configuration is required to set up open-search.

```yaml
pimcore_open_search_client:
clients:
data_index:
hosts: ['https://opensearch:9200']
password: 'admin'
username: 'admin'
ssl_verification: false
```
45 changes: 0 additions & 45 deletions src/DependencyInjection/Factory/OpenSearchClientFactory.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/DependencyInjection/PimcoreGenericDataIndexExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Exception;
use InvalidArgumentException;
use Pimcore\Bundle\GenericDataIndexBundle\DependencyInjection\Factory\OpenSearchClientFactory;
use Pimcore\Bundle\GenericDataIndexBundle\MessageHandler\DispatchQueueMessagesHandler;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigServiceInterface;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -74,12 +73,6 @@ private function registerIndexServiceParams(ContainerBuilder $container, array $
$definition->setArgument('$searchSettings', $indexSettings['search_settings']);
$definition->setArgument('$systemFieldsSettings', $indexSettings['system_fields_settings']);

$definition = $container->getDefinition(OpenSearchClientFactory::class);
$definition->setArgument('$hosts', $indexSettings['client_params']['hosts']);
$definition->setArgument('$username', $indexSettings['client_params']['username']);
$definition->setArgument('$password', $indexSettings['client_params']['password']);
$definition->setArgument('$sslVerification', $indexSettings['client_params']['ssl_verification']);

$definition = $container->getDefinition(DispatchQueueMessagesHandler::class);
$definition->setArgument('$queueSettings', $indexSettings['queue_settings']);
}
Expand Down
12 changes: 11 additions & 1 deletion src/PimcoreGenericDataIndexBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
namespace Pimcore\Bundle\GenericDataIndexBundle;

use Pimcore\Bundle\GenericDataIndexBundle\DependencyInjection\Compiler\SearchIndexFieldDefinitionPass;
use Pimcore\Bundle\OpenSearchClientBundle\PimcoreOpenSearchClientBundle;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Installer\InstallerInterface;
use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface;
use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
use Pimcore\HttpKernel\BundleCollection\BundleCollection;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class PimcoreGenericDataIndexBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface
class PimcoreGenericDataIndexBundle extends AbstractPimcoreBundle implements
PimcoreBundleAdminClassicInterface,
DependentBundleInterface
{
use BundleAdminClassicTrait;

Expand All @@ -40,4 +45,9 @@ public function getInstaller(): ?InstallerInterface
/** @var InstallerInterface|null */
return $this->container->get(Installer::class);
}

public static function registerDependentBundles(BundleCollection $collection): void
{
$collection->addBundle(new PimcoreOpenSearchClientBundle());
}
}

0 comments on commit 59a2163

Please sign in to comment.