List of usage examples for org.apache.lucene.util Version parse
public static Version parse(String version) throws ParseException
From source file:io.crate.expression.reference.sys.check.cluster.LuceneVersionChecks.java
License:Apache License
static boolean isUpgradeRequired(@Nullable String versionStr) { if (versionStr == null || versionStr.isEmpty()) { return false; }/*from w w w . j a v a 2s .c om*/ try { return !Version.parse(versionStr).onOrAfter(Version.LATEST); } catch (ParseException e) { throw new IllegalArgumentException("'" + versionStr + "' is not a valid Lucene version"); } }
From source file:org.codelibs.elasticsearch.common.lucene.Lucene.java
License:Apache License
public static Version parseVersion(@Nullable String version, Version defaultVersion, Logger logger) { if (version == null) { return defaultVersion; }//from w w w . j a va2 s . c om try { return Version.parse(version); } catch (ParseException e) { logger.warn((Supplier<?>) () -> new ParameterizedMessage("no version match {}, default to {}", version, defaultVersion), e); return defaultVersion; } }
From source file:org.dspace.app.util.IndexVersion.java
License:BSD License
/** * Determine the version of Solr/Lucene which was used to create a given index directory. * /*from ww w . j a va 2s . c o m*/ * @param indexDirPath * Full path of the Solr/Lucene index directory * @return version as a string (e.g. "4.4"), empty string ("") if index directory is empty, * or null if directory doesn't exist. * @throws IOException */ public static String getIndexVersion(String indexDirPath) throws IOException { String indexVersion = null; // Make sure this directory exists File dir = new File(indexDirPath); if (dir.exists() && dir.isDirectory()) { // Check if this index directory has any contents String[] dirContents = dir.list(); // If this directory is empty, return an empty string. // It is a valid directory, but it's an empty index. if (dirContents != null && dirContents.length == 0) { return ""; } // Open this index directory in Lucene Directory indexDir = FSDirectory.open(dir); // Get info on the Lucene segment file(s) in index directory SegmentInfos sis = new SegmentInfos(); try { sis.read(indexDir); } catch (IOException ie) { // Wrap default IOException, providing more info about which directory cannot be read throw new IOException("Could not read Lucene segments files in " + dir.getAbsolutePath(), ie); } // If we have a valid Solr index dir, but it has no existing segments // then just return an empty string. It's a valid but empty index. if (sis != null && sis.size() == 0) { return ""; } // Loop through our Lucene segment files to locate the OLDEST // version. It is possible for individual segment files to be // created by different versions of Lucene. So, we just need // to find the oldest version of Lucene which created these // index segment files. // This logic borrowed from Lucene v.4.10 CheckIndex class: // https://github.com/apache/lucene-solr/blob/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java#L426 // WARNING: It MAY require updating whenever we upgrade the // "lucene.version" in our DSpace Parent POM Version oldest = null; Version oldSegment = null; for (SegmentCommitInfo si : sis) { // Get the version of Lucene which created this segment file Version version = si.info.getVersion(); if (version == null) { // If null, then this is a pre-3.1 segment file. // For our purposes, we will just assume it is "3.0", // This lets us know we will need to upgrade it to 3.5 // before upgrading to Solr/Lucene 4.x or above try { oldSegment = Version.parse("3.0"); } catch (ParseException pe) { throw new IOException(pe); } } // else if this segment is older than our oldest thus far else if (oldest == null || version.onOrAfter(oldest) == false) { // We have a new oldest segment version oldest = version; } } // If we found a really old segment, compare it to the oldest // to see which is actually older if (oldSegment != null && oldSegment.onOrAfter(oldest) == false) { oldest = oldSegment; } // At this point, we should know what version of Lucene created our // oldest segment file. We will return this as the Index version // as it's the oldest segment we will need to upgrade. if (oldest != null) { indexVersion = oldest.toString(); } } return indexVersion; }