Thursday, August 11, 2011

How to reindex manually using sql query?

Create a file called “reindex.php” inside your magento root folder and put the following code.
<?php
    require_once 'app/Mage.php';
    umask( 0 );
    Mage :: app( "default" );
    echo "Started Rebuilding Search Index At: " . date("d/m/y h:i:s");
//Locate the correct table. For example here im reindexing catalogsearch_fulltext table.
    $sql = "truncate catalogsearch_fulltext";
    $mysqli = Mage::getSingleton('core/resource')->getConnection('core_write');
    $mysqli->query($sql);
    /*
    Process_id     Indexer_code
        1     catalog_product_attribute
        2     catalog_product_price
        3     catalog_url
        4     catalog_product_flat
        5     catalog_category_flat
        6     catalog_category_product
        7     catalogsearch_fulltext
        8     cataloginventory_stock
        9     tag_summary
    */
    $process = Mage::getModel('index/process')->load(7);
    $process->reindexAll();
    echo "Finished Rebuilding Search Index At: " . date("d/m/y h:i:s");
?>
Then run this script by visiting www.yourdomain.com/reindex.php in your browser.
Then clear your cache.

No comments:

Post a Comment