0

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.

1 Answer 1

1

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

5
  • Unfortunatelly your code still gives me an error:
    – jimmy
    Commented Oct 12, 2016 at 14:45
  • SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (product_id IN ('64334'))' at line 1
    – jimmy
    Commented Oct 12, 2016 at 14:45
  • Little bit tweaked and works as charm. Thank you.
    – jimmy
    Commented Oct 18, 2016 at 21:20
  • I'm glad to hear that, sorry for my late response. Did you find out why it did not run at your environment in the first place? Since there is no query involved, i'm curious what caused. Are your tweaks worth adding up to the answer?
    – FROSIT
    Commented Oct 18, 2016 at 21:31
  • Thank you once again for your answer. I have more complicated issue related to custom catalogsearch fulltext table changes and sphinx search. This is totally not releated to my basic question, so let's just skip these details.
    – jimmy
    Commented Oct 18, 2016 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.