Search in sources :

Example 1 with LuceneIndexer

use of gate.creole.annic.lucene.LuceneIndexer in project gate-core by GateNLP.

the class LuceneDataStoreImpl method open.

// close()
/**
 * Open a connection to the data store.
 */
@Override
public void open() throws PersistenceException {
    super.open();
    /*
     * check if the storage directory is a valid serial datastore if we
     * want to support old style: String versionInVersionFile = "1.0";
     * (but this means it will open *any* directory)
     */
    BufferedReader isr = null;
    try {
        isr = new BufferedReader(new FileReader(getVersionFile()));
        currentProtocolVersion = isr.readLine();
        String indexDirRelativePath = isr.readLine();
        if (indexDirRelativePath != null && indexDirRelativePath.trim().length() > 1) {
            URL storageDirURL = storageDir.toURI().toURL();
            URL theIndexURL = new URL(storageDirURL, indexDirRelativePath);
            // check if index directory exists
            File indexDir = Files.fileFromURL(theIndexURL);
            if (!indexDir.exists()) {
                throw new PersistenceException("Index directory " + indexDirRelativePath + " could not be found for datastore at " + storageDirURL);
            }
            indexURL = theIndexURL;
            this.indexer = new LuceneIndexer(indexURL);
            this.searcher = new LuceneSearcher();
            ((LuceneSearcher) this.searcher).setLuceneDatastore(this);
        }
    } catch (IOException e) {
        throw new PersistenceException("Invalid storage directory: " + e);
    } finally {
        IOUtils.closeQuietly(isr);
    }
    if (!isValidProtocolVersion(currentProtocolVersion))
        throw new PersistenceException("Invalid protocol version number: " + currentProtocolVersion);
    // Lets create a separate indexer thread which keeps running in the
    // background
    executor = new ScheduledThreadPoolExecutor(1, Executors.defaultThreadFactory());
    // set up the executor so it does not execute delayed indexing tasks
    // that are still waiting when it is shut down. We run these tasks
    // immediately at shutdown time rather than waiting.
    executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    // start listening to Creole events
    Gate.getCreoleRegister().addCreoleListener(this);
}
Also used : LuceneSearcher(gate.creole.annic.lucene.LuceneSearcher) LuceneIndexer(gate.creole.annic.lucene.LuceneIndexer) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Aggregations

LuceneIndexer (gate.creole.annic.lucene.LuceneIndexer)1 LuceneSearcher (gate.creole.annic.lucene.LuceneSearcher)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1