Example usage for org.apache.lucene.index IndexUpgrader IndexUpgrader

List of usage examples for org.apache.lucene.index IndexUpgrader IndexUpgrader

Introduction

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

Prototype

public IndexUpgrader(Directory dir, IndexWriterConfig iwc, boolean deletePriorCommits) 

Source Link

Document

Creates index upgrader on the given directory, using an IndexWriter using the given config.

Usage

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

License:Open Source License

private void upgradeIndex(Directory dir) throws IOException {
    boolean doUpgrade = false;
    IndexWriterConfig iwc = new IndexWriterConfig(null);

    CheckIndex chkIndex = new CheckIndex(dir);

    try {//w  ww.j  a va  2s .c  o m
        for (CheckIndex.Status.SegmentInfoStatus segmentInfo : chkIndex.checkIndex().segmentInfos) {
            if (!segmentInfo.version.equals(Version.LATEST)) {
                logInfo("Found Index version %s", segmentInfo.version.toString());
                doUpgrade = true;
                break;
            }
        }
    } finally {
        chkIndex.close();
    }

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

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   ww  w  .  j a  va  2s. co  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();
    }
}