Example usage for org.apache.lucene.index SegmentInfos readCommit

List of usage examples for org.apache.lucene.index SegmentInfos readCommit

Introduction

In this page you can find the example usage for org.apache.lucene.index SegmentInfos readCommit.

Prototype

public static final SegmentInfos readCommit(Directory directory, String segmentFileName) throws IOException 

Source Link

Document

Read a particular segmentFileName.

Usage

From source file:com.vmware.xenon.services.common.LuceneDocumentIndexService.java

License:Open Source License

private void upgradeIndex(Directory dir) throws IOException {
    boolean doUpgrade = false;

    String lastSegmentsFile = SegmentInfos.getLastCommitSegmentsFileName(dir.listAll());
    SegmentInfos sis = SegmentInfos.readCommit(dir, lastSegmentsFile);
    for (SegmentCommitInfo commit : sis) {
        if (!commit.info.getVersion().equals(Version.LATEST)) {
            logInfo("Found Index version %s", commit.info.getVersion().toString());
            doUpgrade = true;/*from w  ww.j a va 2  s .c  o  m*/
            break;
        }
    }

    if (doUpgrade) {
        logInfo("Upgrading index to %s", Version.LATEST.toString());
        IndexWriterConfig iwc = new IndexWriterConfig(null);
        new IndexUpgrader(dir, iwc, false).upgrade();
        this.indexUpdateTimeMicros = Utils.getNowMicrosUtc();
    }
}

From source file:org.apache.solr.handler.IndexFetcher.java

License:Apache License

private boolean hasUnusedFiles(Directory indexDir, IndexCommit commit) throws IOException {
    String segmentsFileName = commit.getSegmentsFileName();
    SegmentInfos infos = SegmentInfos.readCommit(indexDir, segmentsFileName);
    Set<String> currentFiles = new HashSet<>(infos.files(true));
    String[] allFiles = indexDir.listAll();
    for (String file : allFiles) {
        if (!file.equals(segmentsFileName) && !currentFiles.contains(file) && !file.endsWith(".lock")) {
            LOG.info("Found unused file: " + file);
            return true;
        }//from   w  w w. j  a  va 2s .  c  o  m
    }
    return false;
}

From source file:org.codelibs.elasticsearch.common.lucene.Lucene.java

License:Apache License

/**
 * Reads the segments infos from the given commit, failing if it fails to load
 *//* ww w  . jav a 2s.  c o m*/
public static SegmentInfos readSegmentInfos(IndexCommit commit) throws IOException {
    // Using commit.getSegmentsFileName() does NOT work here, have to
    // manually create the segment filename
    String filename = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "",
            commit.getGeneration());
    return SegmentInfos.readCommit(commit.getDirectory(), filename);
}

From source file:org.codelibs.elasticsearch.common.lucene.Lucene.java

License:Apache License

/**
 * Reads the segments infos from the given segments file name, failing if it fails to load
 *//*from  w ww .j  a v  a  2  s.  c  om*/
private static SegmentInfos readSegmentInfos(String segmentsFileName, Directory directory) throws IOException {
    return SegmentInfos.readCommit(directory, segmentsFileName);
}