<?php declare(strict_types=1);
namespace Swag\EnterpriseSearch\Relevance\Bridge;
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;
/**
* @deprecated: Will be removed with the drop of shopware 6.2 support - Use {@see \Swag\EnterpriseSearch\Relevance\ElasticsearchHelperDecorator} instead
*/
class ElasticsearchHelperDecorator extends ElasticsearchHelper
{
/**
* @var ElasticsearchHelper
*/
private $decorated;
/**
* @var TermQueryBuilder
*/
private $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);
}
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();
}
/**
* @deprecated tag:v6.5.0 - Parameter $criteria will be required
*/
public function allowSearch(EntityDefinition $definition, Context $context, ?Criteria $criteria = null): bool
{
try {
return $this->decorated->allowSearch($definition, $context, $criteria);
} catch (\RuntimeException $e) {
return false;
}
}
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);
}
}