Skip to content

Instantly share code, notes, and snippets.

@dodie
Last active September 17, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodie/8eef79f009f1b87d796d9ea628fad2d6 to your computer and use it in GitHub Desktop.
Save dodie/8eef79f009f1b87d796d9ea628fad2d6 to your computer and use it in GitHub Desktop.
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