Skip to content

Commit 09b16a8

Browse files
committed
MC-18332: Remove MySQL Search Engine
- refactor scopes and index structure
1 parent ffc02b9 commit 09b16a8

File tree

5 files changed

+40
-58
lines changed

5 files changed

+40
-58
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ class Fulltext implements
5555

5656
/**
5757
* @var IndexSwitcherInterface
58+
* @deprecated
59+
* @see \Magento\Elasticsearch
5860
*/
5961
private $indexSwitcher;
6062

6163
/**
6264
* @var \Magento\CatalogSearch\Model\Indexer\Scope\State
65+
* @deprecated
66+
* @see \Magento\Elasticsearch
6367
*/
6468
private $indexScopeState;
6569

@@ -136,13 +140,9 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
136140
);
137141

138142
if (null === $entityIds) {
139-
$this->indexScopeState->useTemporaryIndex();
140143
$saveHandler->cleanIndex($dimensions);
141144
$saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId));
142145

143-
$this->indexSwitcher->switchIndex($dimensions);
144-
$this->indexScopeState->useRegularIndex();
145-
146146
$this->fulltextResource->resetSearchResultsByStore($storeId);
147147
} else {
148148
// internal implementation works only with array

app/code/Magento/CatalogSearch/Model/Indexer/IndexStructure.php

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
namespace Magento\CatalogSearch\Model\Indexer;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\App\ResourceConnection;
10-
use Magento\Framework\DB\Adapter\AdapterInterface;
11-
use Magento\Framework\DB\Ddl\Table;
1211
use Magento\Framework\Indexer\IndexStructureInterface;
1312
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
1413
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
@@ -21,83 +20,72 @@
2120
*/
2221
class IndexStructure implements IndexStructureInterface
2322
{
23+
/**
24+
* @var IndexStructureInterface
25+
*/
26+
private $indexStructureEntity;
27+
28+
/**
29+
* @var IndexStructureFactory
30+
*/
31+
private $indexStructureFactory;
32+
2433
/**
2534
* @var Resource
35+
* @deprecated
36+
* @see \Magento\Elasticsearch
2637
*/
2738
private $resource;
2839

2940
/**
3041
* @var IndexScopeResolver
42+
* @deprecated
43+
* @see \Magento\Elasticsearch
3144
*/
3245
private $indexScopeResolver;
3346

3447
/**
3548
* @param ResourceConnection $resource
3649
* @param IndexScopeResolverInterface $indexScopeResolver
50+
* @param IndexStructureFactory|null $indexStructureFactory
3751
*/
3852
public function __construct(
3953
ResourceConnection $resource,
40-
IndexScopeResolverInterface $indexScopeResolver
54+
IndexScopeResolverInterface $indexScopeResolver,
55+
IndexStructureFactory $indexStructureFactory = null
4156
) {
4257
$this->resource = $resource;
4358
$this->indexScopeResolver = $indexScopeResolver;
59+
$this->indexStructureFactory = $indexStructureFactory ? : ObjectManager::getInstance()
60+
->get(IndexStructureFactory::class);
4461
}
4562

4663
/**
4764
* @inheritdoc
4865
*/
4966
public function delete($index, array $dimensions = [])
5067
{
51-
$tableName = $this->indexScopeResolver->resolve($index, $dimensions);
52-
if ($this->resource->getConnection()->isTableExists($tableName)) {
53-
$this->resource->getConnection()->dropTable($tableName);
54-
}
68+
return $this->getEntity()->delete($index, $dimensions);
5569
}
5670

5771
/**
5872
* @inheritdoc
5973
*/
6074
public function create($index, array $fields, array $dimensions = [])
6175
{
62-
$this->createFulltextIndex($this->indexScopeResolver->resolve($index, $dimensions));
76+
return $this->getEntity()->create($index, $fields, $dimensions);
6377
}
6478

6579
/**
66-
* Create fulltext index table.
80+
* Get instance of current index structure
6781
*
68-
* @param string $tableName
69-
* @throws \Zend_Db_Exception
70-
* @return void
82+
* @return IndexStructureInterface
7183
*/
72-
protected function createFulltextIndex($tableName)
84+
private function getEntity()
7385
{
74-
$table = $this->resource->getConnection()->newTable($tableName)
75-
->addColumn(
76-
'entity_id',
77-
Table::TYPE_INTEGER,
78-
10,
79-
['unsigned' => true, 'nullable' => false],
80-
'Entity ID'
81-
)->addColumn(
82-
'attribute_id',
83-
Table::TYPE_INTEGER,
84-
10,
85-
['unsigned' => true, 'nullable' => false]
86-
)->addColumn(
87-
'data_index',
88-
Table::TYPE_TEXT,
89-
'4g',
90-
['nullable' => true],
91-
'Data index'
92-
)->addIndex(
93-
'idx_primary',
94-
['entity_id', 'attribute_id'],
95-
['type' => AdapterInterface::INDEX_TYPE_PRIMARY]
96-
)->addIndex(
97-
'FTI_FULLTEXT_DATA_INDEX',
98-
['data_index'],
99-
['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
100-
);
101-
$this->resource->getConnection()->createTable($table);
86+
if (empty($this->indexStructureEntity)) {
87+
$this->indexStructureEntity = $this->indexStructureFactory->create();
88+
}
89+
return $this->indexStructureEntity;
10290
}
10391
}

app/code/Magento/CatalogSearch/Model/Indexer/IndexStructureProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
/**
1111
* Catalog search index structure proxy.
12+
*
13+
* @deprecated
14+
* @see \Magento\Elasticsearch
1215
*/
1316
class IndexStructureProxy implements IndexStructureInterface
1417
{

app/code/Magento/CatalogSearch/Model/Indexer/Scope/ScopeProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/**
1212
* Implementation of IndexScopeResolverInterface which resolves index scope dynamically depending on current scope state
13+
*
14+
* @deprecated
15+
* @see \Magento\Elasticsearch
1316
*/
1417
class ScopeProxy implements \Magento\Framework\Search\Request\IndexScopeResolverInterface
1518
{

app/code/Magento/CatalogSearch/etc/di.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier"/>
1515
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolver"/>
1616
<preference for="Magento\CatalogSearch\Model\Search\ItemCollectionProviderInterface" type="Magento\CatalogSearch\Model\Search\ItemCollectionProvider"/>
17-
<preference for="Magento\Framework\Indexer\IndexStructureInterface" type="Magento\CatalogSearch\Model\Indexer\IndexStructureProxy" />
17+
<preference for="Magento\Framework\Indexer\IndexStructureInterface" type="Magento\CatalogSearch\Model\Indexer\IndexStructure" />
1818
<type name="Magento\Catalog\Model\Indexer\Product\Full">
1919
<arguments>
2020
<argument name="indexerList" xsi:type="array">
@@ -182,18 +182,6 @@
182182
</argument>
183183
</arguments>
184184
</type>
185-
<type name="Magento\CatalogSearch\Model\Indexer\IndexStructure">
186-
<arguments>
187-
<argument name="indexScopeResolver" xsi:type="object">\Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy</argument>
188-
</arguments>
189-
</type>
190-
<type name="Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy">
191-
<arguments>
192-
<argument name="states" xsi:type="array">
193-
<item name="use_main_table" xsi:type="string">\Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver</item>
194-
</argument>
195-
</arguments>
196-
</type>
197185
<type name="Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerComposite">
198186
<arguments>
199187
<argument name="queryCheckers" xsi:type="array">

0 commit comments

Comments
 (0)