Magento – Couldn’t reindex stock of one item programmatically

indexerindexingmagento-1PHPreindex

I'm trying to reindex one product only programmatically:

$product = Mage::getModel('catalog/product')->load($_productId);
$product->setForceReindexRequired(true);
Mage::getSingleton('index/indexer')->processEntityAction(
    $product,
    Mage_CatalogInventory_Model_Stock_Item::ENTITY,
    Mage_Index_Model_Event::TYPE_SAVE
);

However, nothing is inserted to cataloginventory_stock_status_idx table. But if I reindex using command line:

php indexer.php --reindex cataloginventory_stock

The table is populated.

Best Answer

You should try with:

Mage::getModel('catalogsearch/fulltext')->getResource()->rebuildIndex( 1, (int)$product->getId());