If you use the Zend Lucene Index feature within the Zend Framework then you may have come accross the “Index is under processing now” error message. This this exception will be thrown when an attempt to open or add to a corrupt index is made.
Solution
1. Call optimize(); on the index object periodically. This could be included as part of a cron job that is executed daily for example to prevent potential issues occuring.
2. Handle the exception – if you try to access the index and it has managed to become corrupt, then handle the exception by rebuilding it from scratch. The following example code attempts to open the index; if it is corrupt, it deletes all files within the index directory and then creates it from scratch again. It also logs the error to application/logs (make sure this directory is writeable). Depending on the size of the index, you could re-add all of the records as part of this code, although often that is not pratical due to the amount of records.
try
{
$index = Zend_Search_Lucene::open($dir);
}
catch(Zend_Search_Lucene_Exception $e)
{
if($e->getMessage() == 'Index is under processing now')
{
//index is corrupt - no choice but to delete it and create it from scratch
foreach(glob($dir.'/*') as $v)
{
unlink($v);
}
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/log/index.xml');
$writer->setFormatter(new Zend_Log_Formatter_Xml());
$log = new Zend_Log($writer);
$log->setEventItem('timestamp', date('D, j M Y H:i:s', time()));
$log->debug($e->getMessage() . "::" . get_class($this) . "n" . $e->getTraceAsString());
$index = Zend_Search_Lucene::create($dir);
}
else
{
throw $e;
}
}





