Example usage for org.apache.lucene.util Version parseLeniently

List of usage examples for org.apache.lucene.util Version parseLeniently

Introduction

In this page you can find the example usage for org.apache.lucene.util Version parseLeniently.

Prototype

public static Version parseLeniently(String version) throws ParseException 

Source Link

Document

Parse the given version number as a constant or dot based version.

Usage

From source file:io.yucca.lucene.IndexUtility.java

License:Apache License

public static void main(String[] args) {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    initOptions(options);/*from w w w .  j a va2 s . c  o  m*/
    try {
        final CommandLine line = parser.parse(options, args);
        if (line.hasOption('h')) {
            usage(options);
        }
        if (line.hasOption('s')) {
            String value = line.getOptionValue('s');
            sourceIndexDirectory = new File(value);
            if (sourceIndexDirectory.exists() == false) {
                log.error("Index source directory: {} does not exist!", sourceIndexDirectory);
                System.exit(1);
            }
        } else {
            usage(options);
            System.exit(1);
        }
        if (line.hasOption('d')) {
            String value = line.getOptionValue('d');
            destIndexDirectory = new File(value);
            if (destIndexDirectory.exists() == true) {
                log.error("Index destination directory: {} already exist", destIndexDirectory);
                System.exit(1);
            }
        } else {
            usage(options);
            System.exit(1);
        }
        if (line.hasOption('v')) {
            try {
                String value = line.getOptionValue('v');
                version = Version.parseLeniently(value);
            } catch (Exception e) {
                log.error("Unrecognized index version, exiting");
                usage(options);
                System.exit(1);
            }
        }
        if (line.hasOption('r')) {
            String value = line.getOptionValue('r');
            String[] fields = value.trim().split(" *, *");
            if (fields == null || fields.length == 0) {
                log.error("No fields were given, exiting");
                usage(options);
                System.exit(1);
            }
            (new FieldRemover()).removeFields(sourceIndexDirectory, destIndexDirectory, fields, version);
            System.exit(0);
        }
    } catch (IndexUtilityException e) {
        log.error("Failed to work on index:", e);
        System.exit(1);
    } catch (MissingOptionException e) {
        log.error("Mandatory options is missing!");
        usage(options);
        System.exit(1);
    } catch (ParseException e) {
        log.error("Failed to parse commandline options!");
        usage(options);
        System.exit(1);
    }
}

From source file:org.apache.derby.optional.lucene.LuceneQueryVTI.java

License:Apache License

/**
 * <p>//from   w  ww .  ja v  a2s .co m
 * Make sure that the index wasn't created with a Lucene version from
 * the future.
 * </p>
 */
private void vetLuceneVersion(String indexVersionString) throws SQLException {
    Version currentVersion = LuceneUtils.currentVersion();
    Version indexVersion = null;

    try {
        indexVersion = Version.parseLeniently(indexVersionString);
    } catch (Exception e) {
    }

    if ((indexVersion == null) || !currentVersion.onOrAfter(indexVersion)) {
        throw LuceneSupport.newSQLException(SQLState.LUCENE_BAD_VERSION, currentVersion.toString(),
                indexVersionString);
    }
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.NodeStateAnalyzerFactory.java

License:Apache License

@SuppressWarnings("deprecation")
private static Version parseLuceneVersionString(final String matchVersion) {
    final Version version = Version.parseLeniently(matchVersion);
    if (version == Version.LUCENE_CURRENT && !versionWarningAlreadyLogged.getAndSet(true)) {
        log.warn("You should not use LATEST as luceneMatchVersion property: "
                + "if you use this setting, and then Solr upgrades to a newer release of Lucene, "
                + "sizable changes may happen. If precise back compatibility is important "
                + "then you should instead explicitly specify an actual Lucene version.");
    }//  w w  w .j a v a  2  s.co m
    return version;
}

From source file:org.apache.solr.core.Config.java

License:Apache License

public static final Version parseLuceneVersionString(final String matchVersion) {
    final Version version;
    try {/* w w w  . j  a  v a2  s.  c o  m*/
        version = Version.parseLeniently(matchVersion);
    } catch (IllegalArgumentException iae) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                "Invalid luceneMatchVersion '" + matchVersion + "', valid values are: "
                        + Arrays.toString(Version.values()) + " or a string in format 'V.V'",
                iae);
    }

    if (version == Version.LUCENE_CURRENT && !versionWarningAlreadyLogged.getAndSet(true)) {
        log.warn("You should not use LUCENE_CURRENT as luceneMatchVersion property: "
                + "if you use this setting, and then Solr upgrades to a newer release of Lucene, "
                + "sizable changes may happen. If precise back compatibility is important "
                + "then you should instead explicitly specify an actual Lucene version.");
    }

    return version;
}

From source file:org.hibernate.search.analyzer.impl.LuceneEmbeddedAnalyzerStrategy.java

License:LGPL

private Version getLuceneMatchVersion(SearchConfiguration cfg) {
    final Version version;
    String tmp = cfg.getProperty(Environment.LUCENE_MATCH_VERSION);
    if (StringHelper.isEmpty(tmp)) {
        log.recommendConfiguringLuceneVersion();
        version = Environment.DEFAULT_LUCENE_MATCH_VERSION;
    } else {//from w  w w  . j a v a  2  s.c  om
        try {
            version = Version.parseLeniently(tmp);
            if (log.isDebugEnabled()) {
                log.debug("Setting Lucene compatibility to Version " + version);
            }
        } catch (IllegalArgumentException e) {
            throw log.illegalLuceneVersionFormat(tmp, e.getMessage());
        } catch (ParseException e) {
            throw log.illegalLuceneVersionFormat(tmp, e.getMessage());
        }
    }
    return version;
}

From source file:org.kitesdk.morphline.solr.EnvironmentTest.java

License:Apache License

private static Version getMinorLuceneVersion(String version) {
    try {/*from  w  w  w .  j a  v a2  s. c  o  m*/
        return Version.parseLeniently(version.replaceFirst("^(\\d)\\.(\\d).*", "LUCENE_$1$2"));
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:stroom.index.server.LuceneVersionUtil.java

License:Apache License

public static Version getLuceneVersion(final String indexVersion) {
    try {//  w  ww  .  java 2s  . c o m
        return Version.parseLeniently(indexVersion);
    } catch (final ParseException e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}