Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP script to recreate the mg3_catalogsearch_fulltext_scope1 table for Magento 2.
<?php
try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
echo $e->getMessage();
exit(1);
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
echo 'Startup complete.' . '<br/>';
$indexerHandlerFactory = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\CatalogSearch\\Model\\Indexer\\IndexerHandlerFactory");
$indexerConfig = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\Framework\\Indexer\\ConfigInterface");
$dimensionFactory = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\Framework\\Search\\Request\\DimensionFactory");
try {
$dimensions = [
$dimensionFactory->create(['name' => 'scope', 'value' => 'default'])
];
$configData = $indexerConfig->getIndexer('catalogsearch_fulltext');
$indexHandler = $indexerHandlerFactory->create(['data' => $configData]);
$indexHandler->cleanIndex($dimensions);
} catch(Exception $e) {
echo 'Error recreating catalogsearch_fulltext<br/>';
print($e->getMessage());
}
echo '<br/>';
echo "Successfully recreated catalogsearch_fulltext<br/>";
$indexerFactory = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\Indexer\Model\IndexerFactory");
$indexerIds = array(
'catalog_category_product',
'catalog_product_category',
'catalog_product_price',
'catalog_product_attribute',
'cataloginventory_stock',
'catalogrule_product',
'catalogsearch_fulltext',
);
foreach ($indexerIds as $indexerId) {
try {
echo " create index: ".$indexerId."\n";
$indexer = $indexerFactory->create();
$indexer->load($indexerId);
$indexer->reindexAll();
} catch (\Exception $e) {
echo 'Error reindexing ' . $indexerId . '<br/>';
echo $e->getMessage();
echo "<br/>";
}
}
echo "<br/>";
echo "Done";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.