Magento Indexing of Catalog Products & its Attributes

I have some queries for Magento Indexing Process:

  • First of all, why Magento does not perform the indexing process programmatically, after each Product or any of its Attribute(s) are newly added / modified? Why Admin(s) require to do the indexing, when the indexing processes are very much important & can be done programmatically?
  • In each indexing process, are all the products indexed (including those which have been indexed already), when the “Reindex Data” link is clicked, or only the non-indexed products are indexed?
  • If I want to view / debug the time taken for each indexing process, then what & how will I need to do?

2 thoughts on “Magento Indexing of Catalog Products & its Attributes”

  1. Three part answer, so this should be worth triple points, right? 🙂

    1) Probably because indexing tends to be a computationally intensive task, so rather than slow the site whenever a product is saved (usually during business hours), an Administrator can choose a low-load period, or schedule via cron for the indexing to occur at a typically low-load time.

    2) All products are re-indexed. If you look in Mage_CatalogIndex_Model_Indexer::plainReindex(), you will see that it performs a clear to delete all index data before getting all active products to index.

    $this->_getResource()->clear(
                $attributeCodes,
                $priceAttributeCodes,
                count($priceAttributeCodes)>0,
                count($priceAttributeCodes)>0,
                count($priceAttributeCodes)>0,
                $products,
                $stores
    );
    
    <snip/>
    
    $collection = $this->_getProductCollection($store, $products);
    $collection->addAttributeToFilter(
             'status',
              array('in'=>Mage::getModel('catalog/product_status')->getSaleableStatusIds())
    );
    $this->_walkCollection($collection, $store, $attributeCodes);
    

    where the _walkCollection method creates the index for each product.

    3) You could turn on the Profiler. There are some great blog posts on how to use that. You could wrap the key code in Mage_CatalogIndex_Model_Indexer with Varien_Profiler::start('Indexer') etc to check the time taken.

  2. To expand a bit on Jonathan’s answer, it would be silly to run entire indexes every time a product is saved. Magento’s indexing process for things like category products involves truncating tables and running the index queries again. If you were to save 20 different products, and the indexes were regenerated for each of those, you’d have wasted major time. Since the system can’t guess when you mean to save 20 products in a row, you are instead expected to run your indexes yourself.

Leave a Reply

Your email address will not be published. Required fields are marked *