Example usage for org.apache.lucene.analysis.core SimpleAnalyzer close

List of usage examples for org.apache.lucene.analysis.core SimpleAnalyzer close

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.core SimpleAnalyzer close.

Prototype

@Override
public void close() 

Source Link

Document

Frees persistent resources used by this Analyzer

Usage

From source file:org.hibernate.search.store.spi.DirectoryHelper.java

License:LGPL

/**
 * Initialize the Lucene Directory if it isn't already.
 *
 * @param directory the Directory to initialize
 * @throws SearchException in case of lock acquisition timeouts, IOException, or if a corrupt index is found
 *//*from w  w  w  . j  ava  2  s .co  m*/
public static void initializeIndexIfNeeded(Directory directory) {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    try {
        if (!DirectoryReader.indexExists(directory)) {
            try {
                IndexWriterConfig iwriterConfig = new IndexWriterConfig(analyzer)
                        .setOpenMode(OpenMode.CREATE_OR_APPEND);
                //Needs to have a timeout higher than zero to prevent race conditions over (network) RPCs
                //for distributed indexes (Infinispan but probably also NFS and similar)
                iwriterConfig.setWriteLockTimeout(2000);
                IndexWriter iw = new IndexWriter(directory, iwriterConfig);
                iw.close();
            } catch (LockObtainFailedException lofe) {
                log.lockingFailureDuringInitialization(directory.toString());
            }
        }
    } catch (IOException e) {
        throw new SearchException("Could not initialize index", e);
    } finally {
        analyzer.close();
    }
}