1

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
tombazza
  • 646
  • 9
  • 24

1 Answers1

3

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

file_exists($luceneDir.'segments.gen')
vartec
  • 131,205
  • 36
  • 218
  • 244