Pergunta

I've tried to do these but nothing worked:

Mage::getSingleton('catalogsearch/fulltext')->cleanIndex(null, $productId);
$storeIds = $product->getStoreIds();
foreach($storeIds as $storeId) {
  $searchIndex = ' ' . $product->getName() . ' ' . $product->getSku() . ' ';
  Mage::getResourceModel('catalogsearch/fulltext_engine')->saveEntityIndex($productId, $storeId, $searchIndex);
}

This also didn't work:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection()->addEventsStats();
$observer->getProduct()->getResource()->refreshIndex($observer->getProduct());
Mage::getSingleton('catalogsearch/fulltext')->cleanIndex(null, $productId);
$storeIds = $observer->getProduct()->getStoreIds();
foreach($storeIds as $storeId) {
  Mage::getResourceModel('catalog/product_flat_indexer')->updateProduct($productId, $storeId);
}

This also didn't work:

$product = $observer->getProduct();
$product->setForceReindexRequired(1)->setIsChangedCategories(1);
$product->dataHasChangedFor('name');
$indexerCodes = [
  'catalog_product_attribute',
  'catalog_product_attribute',
  'catalog_product_flat',
  'catalog_product_price',
  'catalogsearch_fulltext',
  'catalog_url'
  'cataloginventory_stock',
  'catalog_category_flat',
  'catalog_category_product',
];

$event = Mage::getSingleton('index/indexer')->logEvent(
  $product,
  $product->getResource()->getType(),
  Mage_Index_Model_Event::TYPE_SAVE,
  false
);

I know that I can find couple of similar questions and answers here and there but I still cannot find fully working solution to reindex only one specific product.

Foi útil?

Solução

It can be done fairly simple for catalogsearch. Here's an example, just tested it.

require_once 'app/Mage.php';
Mage::app();

$store = 1;
$productIds = array(908, 431, 549);

$fullTextModel = Mage::getSingleton('catalogsearch/fulltext');

foreach ($productIds as $productId) {

    if ($fullTextModel->cleanIndex($store, $productId)) {
        echo "cleaned index for product " . $productId . "\n";

        if ($fullTextModel->rebuildIndex($store, $productId)) {
            echo "reindexed index for product " . $productId . "\n";
        }
    }
}

The same can be done for flat catalog product and category indexes, url rewrites, etc. These actions are triggered on product save. I think you needed an example for catalogsearch. This runs on Magento 1.9.2.4

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top