Java Code Examples for org.apache.lucene.index.IndexReader#getCurrentVersion()

The following examples show how to use org.apache.lucene.index.IndexReader#getCurrentVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Index.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @return Creation date of current used search index.
 */
public Date getCreationDate() {
    try {
        final File indexFile = new File(indexPath);
        final Directory directory = FSDirectory.open(indexFile);
        return new Date(IndexReader.getCurrentVersion(directory));
    } catch (final IOException e) {
        return null;
    }
}
 
Example 2
Source File: Index.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @return Creation date of current used search index.
 */
public Date getCreationDate() {
    try {
        final File indexDir = new File(searchModule.getSearchIndexPath());
        final Directory directory = FSDirectory.open(indexDir);
        return new Date(IndexReader.getCurrentVersion(directory));
    } catch (final IOException e) {
        return null;
    }
}
 
Example 3
Source File: Index.java    From olat with Apache License 2.0 5 votes vote down vote up
private void createIndexSearcher(boolean indexNewlyBuilt) {
    try {
        log.info("Create searcher on new index ...");
        Directory searchIndexDirectory = null;
        synchronized (createIndexSearcherLock) {
            closeIndexSearcher();
            if (indexNewlyBuilt) {
                replaceIndexFiles();
            }
            searchIndexDirectory = FSDirectory.open(new File(searchModule.getSearchIndexPath()));
            if (!IndexReader.indexExists(searchIndexDirectory)) {
                log.error("SpellChecker index does not exist [" + searchModule.getSearchIndexPath() + "]");
                return;
            }
            searcher = new IndexSearcher(searchIndexDirectory);
        }

        final long indexTime = IndexReader.getCurrentVersion(searchIndexDirectory);
        if ((System.currentTimeMillis() - indexTime) > maxIndexTime) {
            log.error("Search index is too old [indexDate=" + new Date(indexTime) + "].");
        }

        if (indexNewlyBuilt) {
            log.info("Cleanup old index files ...");
            cleanupIndexFiles();
        }
    } catch (IOException ex) {
        log.error("Searcher couldn't be created.", ex);
    }
}
 
Example 4
Source File: SearchServiceImpl.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * @return Creation date of current used search index.
 */
private Date getCurrentIndexDate() throws IOException {
    final File indexFile = new File(indexPath);
    final Directory directory = FSDirectory.open(indexFile);
    return new Date(IndexReader.getCurrentVersion(directory));
}