Skip to content

Commit

Permalink
Possible fix for indexing bug (close #9 #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
0m3r committed Sep 26, 2022
1 parent d822e61 commit b9805dc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Setup/Patch/Data/MySQLCatalogSearchTableCreation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);

namespace Swissup\SearchMysqlLegacy\Setup\Patch\Data;

use Magento\CatalogSearch\Model\Indexer\IndexStructure;
use Magento\Framework\Indexer\DimensionProviderInterface;
use Magento\Framework\Search\EngineResolverInterface;
use Magento\CatalogSearch\Model\Indexer\Fulltext;

/**
* This patch will create catalogsearch_fulltext tables in MySQL DB.
*/
class MySQLCatalogSearchTableCreation implements \Magento\Framework\Setup\Patch\DataPatchInterface
{
/**
* @var IndexStructure
*/
private $indexStructure;

/**
* @var DimensionProviderInterface
*/
private $dimensionProvider;

/**
* @var EngineResolverInterface
*/
private $searchEngineResolver;

/**
* MySQLCatalogSearchTableCreation constructor.
* @param IndexStructure $indexStructure
* @param DimensionProviderInterface $dimensionProvider
* @param EngineResolverInterface $searchEngineResolver
*/
public function __construct(
IndexStructure $indexStructure,
DimensionProviderInterface $dimensionProvider,
EngineResolverInterface $searchEngineResolver
) {
$this->indexStructure = $indexStructure;
$this->dimensionProvider = $dimensionProvider;
$this->searchEngineResolver = $searchEngineResolver;
}

/**
* @inheritdoc
*/
public function apply()
{
if ($this->searchEngineResolver->getCurrentSearchEngine() === 'lmysql') {
foreach ($this->dimensionProvider->getIterator() as $dimension) {
$this->indexStructure->create(Fulltext::INDEXER_ID, [], $dimension);
}
}
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}
}
8 changes: 8 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,12 @@
</arguments>
</type>

<type name="Swissup\SearchMysqlLegacy\Setup\Patch\Data\MySQLCatalogSearchTableCreation">
<arguments>
<argument name="dimensionProvider" xsi:type="object" shared="false">
Magento\Store\Model\StoreDimensionProvider
</argument>
</arguments>
</type>

</config>

0 comments on commit b9805dc

Please sign in to comment.