List of usage examples for org.apache.lucene.index SegmentInfos getIndexCreatedVersionMajor
public int getIndexCreatedVersionMajor()
From source file:org.opengrok.indexer.index.IndexVersion.java
License:Open Source License
/** * Check index version in given directory. It assumes that that all commits * in the Lucene segment file were done with the same version. * * @param dir directory with index//from ww w . j a v a 2 s.c om * @thows IOException if the directory cannot be opened */ private static void checkDir(File dir) throws Exception { LockFactory lockfact = NativeFSLockFactory.INSTANCE; int segVersion; try (Directory indexDirectory = FSDirectory.open(dir.toPath(), lockfact)) { SegmentInfos segInfos = null; try { segInfos = SegmentInfos.readLatestCommit(indexDirectory); segVersion = segInfos.getIndexCreatedVersionMajor(); } catch (IndexNotFoundException e) { return; } } if (segVersion != Version.LATEST.major) { throw new IndexVersionException(String.format("Directory %s has index of version %d and Lucene has %d", dir.toString(), segVersion, Version.LATEST.major)); } }