124 lines
3.5 KiB
PHP
124 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\LuigisBoxBundle\Search;
|
|
|
|
use KupShop\CatalogBundle\Search\FulltextElastic;
|
|
use KupShop\CatalogBundle\Search\FulltextInterface;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use KupShop\KupShopBundle\Util\Compat\SymfonyBridge;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
class FulltextSearchProxy implements FulltextInterface
|
|
{
|
|
#[Required]
|
|
public RequestStack $requestStack;
|
|
|
|
protected function getFulltextService(): FulltextInterface
|
|
{
|
|
if (!($request = $this->requestStack->getMainRequest())) {
|
|
$request = SymfonyBridge::getCurrentRequest();
|
|
}
|
|
|
|
$lbEnabled = (\Settings::getDefault()->analytics['luigis_box']['search'] ?? 'N');
|
|
$lbEnabled = match ($lbEnabled) {
|
|
'Y' => true,
|
|
'A' => !empty(getAdminUser()),
|
|
default => false,
|
|
};
|
|
|
|
if (!$lbEnabled || $request->cookies->get('convert_lb_disable')) { // disable LB fulltext
|
|
return ServiceContainer::getService(FulltextElastic::class);
|
|
}
|
|
|
|
return ServiceContainer::getService(FulltextLuigisBox::class);
|
|
}
|
|
|
|
public function setCurlTimeout($timeout): FulltextInterface
|
|
{
|
|
return $this->getFulltextService()->setCurlTimeout($timeout);
|
|
}
|
|
|
|
public function getIndexTypes(): array
|
|
{
|
|
return $this->getFulltextService()->getIndexTypes();
|
|
}
|
|
|
|
public function search(string $term, array $config, array $types = []): array
|
|
{
|
|
return $this->getFulltextService()->search($term, $config, $types);
|
|
}
|
|
|
|
public function searchProducts($term, $count, $offset, $order = null, $filter = '')
|
|
{
|
|
return $this->getFulltextService()->searchProducts($term, $count, $offset, $order, $filter);
|
|
}
|
|
|
|
public function searchProductsExact($term, $count, $offset, $order = null, $filter = '')
|
|
{
|
|
return $this->getFulltextService()->searchProductsExact($term, $count, $offset, $order, $filter);
|
|
}
|
|
|
|
public function getRowsCount()
|
|
{
|
|
return $this->getFulltextService()->getRowsCount();
|
|
}
|
|
|
|
public function suggestTerm($term)
|
|
{
|
|
return $this->getFulltextService()->suggestTerm($term);
|
|
}
|
|
|
|
public function updateProduct($id_product)
|
|
{
|
|
return $this->getFulltextService()->updateProduct($id_product);
|
|
}
|
|
|
|
public function loadSynonyms(): array
|
|
{
|
|
return $this->getFulltextService()->loadSynonyms();
|
|
}
|
|
|
|
public function loadSynonymsFromIndex(): ?array
|
|
{
|
|
return $this->getFulltextService()->loadSynonymsFromIndex();
|
|
}
|
|
|
|
public function updateSynonyms(array $synonyms, bool $merge = false): void
|
|
{
|
|
$this->getFulltextService()->updateSynonyms($synonyms, $merge);
|
|
}
|
|
|
|
public function saveSynonyms(array $synonyms): void
|
|
{
|
|
$this->getFulltextService()->saveSynonyms($synonyms);
|
|
}
|
|
|
|
public function updateIndex(string $type = 'all', $clean = true, array $exceptTypes = []): void
|
|
{
|
|
$this->getFulltextService()->updateIndex($type);
|
|
}
|
|
|
|
public function getFilters(): array
|
|
{
|
|
return $this->getFulltextService()->getFilters();
|
|
}
|
|
|
|
public function setDynamicFilters(array $filters): void
|
|
{
|
|
$this->getFulltextService()->setDynamicFilters($filters);
|
|
}
|
|
|
|
public function getFulltextLanguages(): array
|
|
{
|
|
return $this->getFulltextService()->getFulltextLanguages();
|
|
}
|
|
|
|
public function supportsFilters(): bool
|
|
{
|
|
return $this->getFulltextService()->supportsFilters();
|
|
}
|
|
}
|