b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / Mirasvit / Search / Model /
Filename/home/Mirasvit/Search/Model/ConfigProvider.php
Size7.2 kb
Permissionrwxr-xr-x
Ownerroot : root
Create time01-Jul-2024 20:52
Last modified06-Apr-2021 18:06
Last accessed21-Aug-2025 18:42
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Mirasvit
*
* This source file is subject to the Mirasvit Software License, which is available at https://mirasvit.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to http://www.magentocommerce.com for more information.
*
* @category Mirasvit
* @package mirasvit/module-search-ultimate
* @version 2.0.25
* @copyright Copyright (C) 2021 Mirasvit (https://mirasvit.com/)
*/


declare(strict_types=1);

namespace Mirasvit\Search\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Store\Model\ScopeInterface;
use Mirasvit\Search\Api\Data\QueryConfigProviderInterface;
use Magento\Store\Model\StoreManagerInterface;
use Mirasvit\Search\Service\SynonymService;
use Mirasvit\Search\Service\StopwordService;
use Mirasvit\Search\Service\StemmingService;

class ConfigProvider implements QueryConfigProviderInterface
{
private $scopeConfig;

private $filesystem;

private $storeManager;

private $synonymService;

private $stopwordService;

private $stemmingService;

public function __construct(
ScopeConfigInterface $scopeConfig,
Filesystem $filesystem,
StoreManagerInterface $storeManager,
SynonymService $synonymService,
StopwordService $stopwordService,
StemmingService $stemmingService
) {
$this->scopeConfig = $scopeConfig;
$this->filesystem = $filesystem;
$this->storeManager = $storeManager;
$this->synonymService = $synonymService;
$this->stopwordService = $stopwordService;
$this->stemmingService = $stemmingService;
}

public function getStoreId(): int
{
return (int) $this->storeManager->getStore()->getId();
}

public function getEngine(): string
{
return $this->scopeConfig->getValue('catalog/search/engine', ScopeInterface::SCOPE_STORE);
}

public function getLongTailExpressions(): array
{
if ($this->scopeConfig->getValue('search/advanced/long_tail_expressions', ScopeInterface::SCOPE_STORE) !== null) {
$data = \Zend_Json::decode(
$this->scopeConfig->getValue('search/advanced/long_tail_expressions', ScopeInterface::SCOPE_STORE)
);
} else {
$data = [];
}

if (is_array($data)) {
return array_values($data);
}

return [];
}

public function getReplaceWords(): array
{
if ($this->scopeConfig->getValue('search/advanced/replace_words', ScopeInterface::SCOPE_STORE) !== null) {
$data = \Zend_Json::decode(
$this->scopeConfig->getValue('search/advanced/replace_words', ScopeInterface::SCOPE_STORE)
);
} else {
$data = [];
}

if (is_array($data)) {
$result = [];
foreach ($data as $item) {
$from = explode(',', $item['from']);

foreach ($from as $f) {
$result[] = [
'from' => trim($f),
'to' => trim($item['to']),
];
}
}

return $result;
}

return [];
}

public function getNotWords(): array
{
$result = [];
if ($this->scopeConfig->getValue('search/advanced/not_words', ScopeInterface::SCOPE_STORE) !== null) {
$data = \Zend_Json::decode(
$this->scopeConfig->getValue('search/advanced/not_words', ScopeInterface::SCOPE_STORE)
);
} else {
$data = [];
}


if (is_array($data)) {
foreach ($data as $row) {
$result[] = $row['exception'];
}
}

return $result;
}


public function getWildcardMode(): string
{
return $this->scopeConfig->getValue('search/advanced/wildcard', ScopeInterface::SCOPE_STORE);
}

public function getMatchMode(): string
{
return $this->scopeConfig->getValue('search/advanced/match_mode', ScopeInterface::SCOPE_STORE);
}

public function getWildcardExceptions(): array
{
$result = [];
if ($this->scopeConfig->getValue('search/advanced/wildcard_exceptions', ScopeInterface::SCOPE_STORE) !== null) {
$data = \Zend_Json::decode(
$this->scopeConfig->getValue('search/advanced/wildcard_exceptions', ScopeInterface::SCOPE_STORE)
);
} else {
$data = [];
}

if (is_array($data) && !empty($data)) {
foreach ($data as $row) {
$result[] = $row['exception'];
}
}

return $result;
}

public function is404ToSearch(): bool
{
return (bool)$this->scopeConfig->getValue('search/feature/noroute_to_search', ScopeInterface::SCOPE_STORE);
}

public function isRedirectOnSingleResult(): bool
{
return (bool)$this->scopeConfig->getValue('search/feature/redirect_on_single_result', ScopeInterface::SCOPE_STORE);
}

public function isHighlightingEnabled(): bool
{
return (bool)$this->scopeConfig->getValue('search/feature/terms_highlighting', ScopeInterface::SCOPE_STORE);
}

public function isAddGoogleSiteLinks(): bool
{
return (bool)$this->scopeConfig->getValue('search/feature/google_sitelinks', ScopeInterface::SCOPE_STORE);
}

public function isMultiStoreModeEnabled(): bool
{
return (bool)$this->scopeConfig->getValue('search/multi_store_mode/enabled', ScopeInterface::SCOPE_STORE);
}

/**
* @return array
*/
public function getEnabledMultiStores()
{
return explode(
',',
$this->scopeConfig->getValue('search/multi_store_mode/stores', ScopeInterface::SCOPE_STORE)
);
}

/**
* Stopwords paths
* @return string Full path to directory with stopwords
*/
public function getStopwordDirectoryPath()
{
return $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR)
->getAbsolutePath('sphinx/stopwords');
}

/**
* Synonyms path
* @return string Full path to directory with synonyms
*/
public function getSynonymDirectoryPath()
{
return $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR)
->getAbsolutePath('sphinx/synonyms');
}

/**
* @return bool
*/
public function isFastMode()
{
return $this->scopeConfig->isSetFlag('searchautocomplete/general/fast_mode');
}

public function getTabsThreshold(): int
{
return (int)$this->scopeConfig->getValue('search/feature/tabs_threshold');
}

public function getSynonyms(array $terms, int $storeId): array
{
return $this->synonymService->getSynonyms($terms, $storeId);
}

public function isStopword(string $term, int $storeId): bool
{
return $this->stopwordService->isStopword($term, $storeId);
}

public function applyStemming(string $term): string
{
return $this->stemmingService->singularize($term);
}
}