Question

I am looking for a reliable way to check to see if a directory contains a Zend_Search_Lucene index. Currently, the only way I have managed to work this out is to check the contents of an exception returned to me using the following code:

<?php
try
{
    $newIndex = Zend_Search_Lucene::open( $luceneDir );
} catch ( Zend_Search_Lucene_Exception $e ) {
    if ( strpos( $e->getMessage( ), 'in the specified directory' ) !== false )
    {
        $newIndex = Zend_Search_Lucene::create( $luceneDir );
    }
}
?>

This method is not ideal, and a check of the API did not seem very useful. Does anyone know if there is a simple way to see if $luceneDir contains a Zend_Search_Lucene index?

Was it helpful?

Solution

You might first try to check if there is index segments number file

file_exists($luceneDir.'segments.gen')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top