<?php declare(strict_types=1);
namespace Uandi\UandiAvailabilityFilter\Service;
use ONGR\ElasticsearchDSL\Search;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Elasticsearch\Framework\ElasticsearchHelper;
use Swag\EnterpriseSearch\Relevance\InvalidContextSourceException;
use Swag\EnterpriseSearch\Relevance\TermQueryBuilder;
/**
* Implement decorator using EnterpriseSearch as code base
* to handle logging in `logAndThrowException()` method.
*
* @deprecated: Seems to be implemented already in the same way by Shopware.
*
* @see \Swag\EnterpriseSearch\Relevance\Bridge\ElasticsearchHelperDecorator
*/
class ElasticsearchHelperDecorator extends ElasticsearchHelper
{
private ElasticsearchHelper $decorated;
private $termQueryBuilder;
/**
* @param ElasticsearchHelper $decorated
* @param TermQueryBuilder $termQueryBuilder
*/
public function __construct(
ElasticsearchHelper $decorated,
TermQueryBuilder $termQueryBuilder
) {
$this->decorated = $decorated;
$this->termQueryBuilder = $termQueryBuilder;
}
public function addTerm(Criteria $criteria, Search $search, Context $context, ?EntityDefinition $definition = null): void
{
if ($definition) {
try {
$this->termQueryBuilder->addTermQuery($definition, $criteria, $search, $context);
} catch (InvalidContextSourceException $e) {
$this->decorated->addTerm($criteria, $search, $context, $definition);
}
return;
}
$this->decorated->addTerm($criteria, $search, $context, $definition);
}
public function logOrThrowException(\Throwable $exception): bool
{
return $this->decorated->logOrThrowException($exception);
}
/**
* @throws \Throwable
*/
public function logAndThrowException(\Throwable $exception): bool
{
if (method_exists($this->decorated, 'logAndThrowException')) {
return $this->decorated->logAndThrowException($exception);
}
return false;
}
public function getIndexName(EntityDefinition $definition, string $languageId): string
{
return $this->decorated->getIndexName($definition, $languageId);
}
public function allowIndexing(): bool
{
return $this->decorated->allowIndexing();
}
public function allowSearch(EntityDefinition $definition, Context $context): bool
{
return $this->decorated->allowSearch($definition, $context);
}
public function handleIds(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->handleIds($definition, $criteria, $search, $context);
}
public function addFilters(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->addFilters($definition, $criteria, $search, $context);
}
public function addPostFilters(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->addPostFilters($definition, $criteria, $search, $context);
}
public function addQueries(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->addQueries($definition, $criteria, $search, $context);
}
public function addSortings(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->addSortings($definition, $criteria, $search, $context);
}
public function addAggregations(EntityDefinition $definition, Criteria $criteria, Search $search, Context $context): void
{
$this->decorated->addAggregations($definition, $criteria, $search, $context);
}
public function setEnabled(bool $enabled): ElasticsearchHelper
{
return $this->decorated->setEnabled($enabled);
}
public function isSupported(EntityDefinition $definition): bool
{
return $this->decorated->isSupported($definition);
}
}