public void upgrade() throws IOException {if (!DirectoryReader.indexExists(dir)) {throw new IndexNotFoundException(dir.toString());}if (!deletePriorCommits) {final Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);if (commits.size() > 1) {throw new IllegalArgumentException("This tool was invoked to not delete prior commit points, but the following commits were found: " + commits);}}iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());try (final IndexWriter w = new IndexWriter(dir, iwc)) {InfoStream infoStream = iwc.getInfoStream();if (infoStream.isEnabled(LOG_PREFIX)) {infoStream.message(LOG_PREFIX, "Upgrading all pre-" + Version.LATEST + " segments of index directory '" + dir + "' to version " + Version.LATEST + "...");}w.forceMerge(1);if (infoStream.isEnabled(LOG_PREFIX)) {infoStream.message(LOG_PREFIX, "All segments upgraded to version " + Version.LATEST);infoStream.message(LOG_PREFIX, "Enforcing commit to rewrite all index metadata...");}w.setLiveCommitData(w.getLiveCommitData()); assert w.hasUncommittedChanges();w.commit();if (infoStream.isEnabled(LOG_PREFIX)) {infoStream.message(LOG_PREFIX, "Committed upgraded metadata to index.");}}}
public void Upgrade(){if (!DirectoryReader.IndexExists(dir)){throw new IndexNotFoundException(dir.ToString());}if (!deletePriorCommits){ICollection<IndexCommit> commits = DirectoryReader.ListCommits(dir);if (commits.Count > 1){throw new System.ArgumentException("this tool was invoked to not delete prior commit points, but the following commits were found: " + commits);}}IndexWriterConfig c = (IndexWriterConfig)iwc.Clone();c.MergePolicy = new UpgradeIndexMergePolicy(c.MergePolicy);c.IndexDeletionPolicy = new KeepOnlyLastCommitDeletionPolicy();IndexWriter w = new IndexWriter(dir, c);try{InfoStream infoStream = c.InfoStream;if (infoStream.IsEnabled("IndexUpgrader")){infoStream.Message("IndexUpgrader", "Upgrading all pre-" + Constants.LUCENE_MAIN_VERSION + " segments of index directory '" + dir + "' to version " + Constants.LUCENE_MAIN_VERSION + "...");}w.ForceMerge(1);if (infoStream.IsEnabled("IndexUpgrader")){infoStream.Message("IndexUpgrader", "All segments upgraded to version " + Constants.LUCENE_MAIN_VERSION);}}finally{w.Dispose();}}