Skip to content

Commit bdb409c

Browse files
committed
ACP2E-752: [Magento Cloud][Premier Support] Incorrect search results with Thai language
1 parent 39ed32e commit bdb409c

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/Index/Builder.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,19 @@ class Builder implements BuilderInterface
3838
*/
3939
private $synonymReader;
4040

41-
/**
42-
* @var StoreManagerInterface
43-
*/
44-
private $storeManager;
45-
4641
/**
4742
* @param LocaleResolver $localeResolver
4843
* @param EsConfigInterface $esConfig
4944
* @param SynonymReader $synonymReader
50-
* @param StoreManagerInterface $storeManager
5145
*/
5246
public function __construct(
5347
LocaleResolver $localeResolver,
5448
EsConfigInterface $esConfig,
55-
SynonymReader $synonymReader,
56-
StoreManagerInterface $storeManager
49+
SynonymReader $synonymReader
5750
) {
5851
$this->localeResolver = $localeResolver;
5952
$this->esConfig = $esConfig;
6053
$this->synonymReader = $synonymReader;
61-
$this->storeManager = $storeManager;
6254
}
6355

6456
/**
@@ -204,9 +196,7 @@ protected function getStemmerConfig()
204196
*/
205197
private function getSynonymFilter(): array
206198
{
207-
$this->storeManager->setCurrentStore($this->storeId);
208-
209-
$synonyms = $this->synonymReader->getAllSynonyms();
199+
$synonyms = $this->synonymReader->getAllSynonymsForStoreViewId($this->storeId);
210200
$synonymFilter = [];
211201

212202
if ($synonyms) {

app/code/Magento/Search/Model/ResourceModel/SynonymReader.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1313
use Magento\Store\Model\ScopeInterface;
14+
use Magento\Store\Model\Store;
1415
use Magento\Store\Model\StoreManagerInterface;
1516

1617
/**
@@ -71,20 +72,23 @@ public function loadByPhrase(\Magento\Search\Model\SynonymReader $object, $phras
7172
/**
7273
* Get all synonyms as an array
7374
*
75+
* @param int $storeViewId
76+
* @return array
7477
* @throws LocalizedException
7578
*/
76-
public function getAllSynonyms(): array
79+
public function getAllSynonymsForStoreViewId(int $storeViewId): array
7780
{
7881
$connection = $this->getConnection();
79-
$query = $connection->select()->from($this->getMainTable());
80-
$rows = $connection->fetchAll($query);
81-
$synonymsPerScope = $this->getSynRowsPerScope($rows);
82-
83-
return array_merge(
84-
array_column($synonymsPerScope[ScopeInterface::SCOPE_STORES], 'synonyms'),
85-
array_column($synonymsPerScope[ScopeInterface::SCOPE_WEBSITES], 'synonyms'),
86-
array_column($synonymsPerScope[ScopeConfigInterface::SCOPE_TYPE_DEFAULT], 'synonyms')
87-
);
82+
83+
$storeIdField = $connection
84+
->quoteIdentifier(sprintf('%s.%s', $this->getMainTable(), 'store_id'));
85+
86+
$select = $connection
87+
->select()
88+
->from($this->getMainTable(), 'synonyms')
89+
->where($storeIdField . ' IN (?)', [Store::DEFAULT_STORE_ID, $storeViewId]);
90+
91+
return $connection->fetchCol($select);
8892
}
8993

9094
/**

0 commit comments

Comments
 (0)