* @throws SearchException in case of lock acquisition timeouts, IOException, or if a corrupt index is found
*/
public static void initializeIndexIfNeeded(Directory directory) {
//version doesn't really matter as we won't use the Analyzer
Version version = Environment.DEFAULT_LUCENE_MATCH_VERSION;
SimpleAnalyzer analyzer = new SimpleAnalyzer( version );
try {
if ( ! DirectoryReader.indexExists( directory ) ) {
IndexWriterConfig iwriterConfig = new IndexWriterConfig( version, analyzer ).setOpenMode( OpenMode.CREATE );
IndexWriter iw = new IndexWriter( directory, iwriterConfig );
iw.close();
}
}
catch (IOException e) {
throw new SearchException( "Could not initialize index", e );
}
finally {
analyzer.close();
}
}