Example usage for org.apache.lucene.store FSDirectory toString

List of usage examples for org.apache.lucene.store FSDirectory toString

Introduction

In this page you can find the example usage for org.apache.lucene.store FSDirectory toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:dk.defxws.fgslucene.IndexWriterCache.java

License:Open Source License

public FSDirectory getDirectoryImplementation(String dirImplClassName, File file)
        throws GenericSearchException {
    FSDirectory directory = null;
    if (logger.isDebugEnabled())
        logger.debug("directoryImplementationClassName=" + dirImplClassName);
    try {//from   w  ww.j  a v  a 2 s  .co m
        Class dirImplClass = Class.forName(dirImplClassName);
        if (logger.isDebugEnabled())
            logger.debug("directoryImplementationClass=" + dirImplClass.toString());
        directory = (FSDirectory) dirImplClass.getConstructor(new Class[] { File.class })
                .newInstance(new Object[] { file });
        if (logger.isDebugEnabled())
            logger.debug("directory=" + directory.toString());
    } catch (ClassNotFoundException e) {
        throw new GenericSearchException(dirImplClassName + ": class not found.\n", e);
    } catch (InstantiationException e) {
        throw new GenericSearchException(dirImplClassName + ": instantiation error.\n", e);
    } catch (IllegalAccessException e) {
        throw new GenericSearchException(dirImplClassName + ": instantiation error.\n", e);
    } catch (InvocationTargetException e) {
        throw new GenericSearchException(dirImplClassName + ": instantiation error.\n", e);
    } catch (NoSuchMethodException e) {
        throw new GenericSearchException(dirImplClassName + ": instantiation error.\n", e);
    }
    return directory;
}

From source file:org.sakaiproject.search.journal.impl.JournaledFSIndexStorage.java

License:Educational Community License

private IndexReader getIndexReaderInternal() throws IOException {
    long start = System.currentTimeMillis();
    File f = new File(journalSettings.getSearchIndexDirectory());
    Directory d = null;/*from   ww  w . j a va 2  s .c o m*/
    if (!f.exists()) {
        if (!f.mkdirs()) {
            throw new IOException("can't create index directory " + f.getPath());
        }
        log.debug("Indexing in " + f.getAbsolutePath());
        d = FSDirectory.open(new File(journalSettings.getSearchIndexDirectory()));
    } else {
        d = FSDirectory.open(new File(journalSettings.getSearchIndexDirectory()));
    }

    if (IndexWriter.isLocked(d)) {
        // this could be dangerous, I am assuming that
        // the locking mechanism implemented here is
        // robust and
        // already prevents multiple modifiers.
        // A more

        IndexWriter.unlock(d);
        log.warn("Unlocked Lucene Directory for update, hope this is Ok");
    }
    if (!d.fileExists("segments.gen")) {
        IndexWriter iw = new IndexWriter(FSDirectory.open(f), getAnalyzer(), MaxFieldLength.UNLIMITED);
        iw.setUseCompoundFile(true);
        iw.setMaxMergeDocs(journalSettings.getLocalMaxMergeDocs());
        iw.setMaxBufferedDocs(journalSettings.getLocalMaxBufferedDocs());
        iw.setMergeFactor(journalSettings.getLocalMaxMergeFactor());
        Document doc = new Document();
        doc.add(new Field("indexcreated", (new Date()).toString(), Field.Store.YES, Field.Index.NOT_ANALYZED,
                Field.TermVector.NO));
        iw.addDocument(doc);
        iw.close();
    }

    final IndexReader[] indexReaders = new IndexReader[segments.size() + 1];
    indexReaders[0] = IndexReader.open(d, false);
    int i = 1;
    for (File s : segments) {
        FSDirectory fsd = FSDirectory.open(s);
        if (IndexWriter.isLocked(fsd)) {
            log.warn("++++++++++++++++++Unlocking Index " + fsd.toString());
            IndexWriter.unlock(fsd);
        }
        indexReaders[i] = IndexReader.open(FSDirectory.open(s), false);
        i++;
    }
    RefCountMultiReader newMultiReader = new RefCountMultiReader(indexReaders, this);

    if (multiReader != null) {
        multiReader.close(); // this will postpone due to the override
        // above
    }
    multiReader = newMultiReader;
    lastUpdate = System.currentTimeMillis();

    log.debug("Reopened Index Reader in " + (lastUpdate - start) + " ms");
    // notify anything that wants to listen to the index open and close
    // events
    fireIndexReaderOpen(newMultiReader);
    return multiReader;

}