mirror of https://github.com/apache/lucene.git
SOLR-12365: moved parseLuceneVersionString to SolrConfig class
This commit is contained in:
parent
ff19a3a261
commit
84264c7410
|
@ -28,6 +28,7 @@ import java.net.URL;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
@ -39,6 +40,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -104,6 +106,7 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
|
|||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public static final String DEFAULT_CONF_FILE = "solrconfig.xml";
|
||||
|
||||
private RequestParams requestParams;
|
||||
|
||||
public enum PluginOpts {
|
||||
|
@ -204,7 +207,7 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
|
|||
getOverlay();//just in case it is not initialized
|
||||
getRequestParams();
|
||||
initLibs();
|
||||
luceneMatchVersion = getLuceneVersion("luceneMatchVersion");
|
||||
luceneMatchVersion = SolrConfig.parseLuceneVersionString(getVal("luceneMatchVersion", true));
|
||||
String indexConfigPrefix;
|
||||
|
||||
// Old indexDefaults and mainIndex sections are deprecated and fails fast for luceneMatchVersion=>LUCENE_4_0_0.
|
||||
|
@ -332,6 +335,29 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
|
|||
log.debug("Loaded SolrConfig: {}", name);
|
||||
}
|
||||
|
||||
private static final AtomicBoolean versionWarningAlreadyLogged = new AtomicBoolean(false);
|
||||
|
||||
public static final Version parseLuceneVersionString(final String matchVersion) {
|
||||
final Version version;
|
||||
try {
|
||||
version = Version.parseLeniently(matchVersion);
|
||||
} catch (ParseException pe) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||
"Invalid luceneMatchVersion. Should be of the form 'V.V.V' (e.g. 4.8.0)", pe);
|
||||
}
|
||||
|
||||
if (version == Version.LATEST && !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."
|
||||
);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
public static final List<SolrPluginInfo> plugins = ImmutableList.<SolrPluginInfo>builder()
|
||||
.add(new SolrPluginInfo(SolrRequestHandler.class, SolrRequestHandler.TYPE, REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK, LAZY))
|
||||
.add(new SolrPluginInfo(QParserPlugin.class, "queryParser", REQUIRE_NAME, REQUIRE_CLASS, MULTI_OK))
|
||||
|
|
|
@ -32,7 +32,6 @@ import javax.xml.xpath.XPathFactory;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
@ -42,10 +41,8 @@ import java.util.SortedMap;
|
|||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.util.XMLErrorLogger;
|
||||
|
@ -438,49 +435,13 @@ public class XmlConfigFile { // formerly simply "Config"
|
|||
return val!=null ? Float.parseFloat(val) : def;
|
||||
}
|
||||
|
||||
|
||||
public double getDouble(String path){
|
||||
return Double.parseDouble(getVal(path, true));
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
String val = getVal(path, false);
|
||||
return val!=null ? Double.parseDouble(val) : def;
|
||||
}
|
||||
|
||||
//TODO belongs on SolrXmlConfig?
|
||||
public Version getLuceneVersion(String path) {
|
||||
return parseLuceneVersionString(getVal(path, true));
|
||||
}
|
||||
|
||||
//TODO belongs on SolrXmlConfig?
|
||||
public Version getLuceneVersion(String path, Version def) {
|
||||
String val = getVal(path, false);
|
||||
return val!=null ? parseLuceneVersionString(val) : def;
|
||||
}
|
||||
|
||||
private static final AtomicBoolean versionWarningAlreadyLogged = new AtomicBoolean(false);
|
||||
|
||||
//TODO belongs on SolrXmlConfig?
|
||||
public static final Version parseLuceneVersionString(final String matchVersion) {
|
||||
final Version version;
|
||||
try {
|
||||
version = Version.parseLeniently(matchVersion);
|
||||
} catch (ParseException pe) {
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||
"Invalid luceneMatchVersion. Should be of the form 'V.V.V' (e.g. 4.8.0)", pe);
|
||||
}
|
||||
|
||||
if (version == Version.LATEST && !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."
|
||||
);
|
||||
}
|
||||
|
||||
return version;
|
||||
public double getDouble(String path, double def) {
|
||||
String val = getVal(path, false);
|
||||
return val != null ? Double.parseDouble(val) : def;
|
||||
}
|
||||
|
||||
/**If this config is loaded from zk the version is relevant other wise -1 is returned
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.lucene.analysis.util.TokenizerFactory;
|
|||
import org.apache.lucene.util.Version;
|
||||
import org.apache.solr.analysis.TokenizerChain;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.core.XmlConfigFile;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
import org.apache.solr.util.DOMUtil;
|
||||
import org.apache.solr.util.plugin.AbstractPluginLoader;
|
||||
|
@ -231,7 +231,7 @@ public final class FieldTypePluginLoader
|
|||
final String matchVersionStr = DOMUtil.getAttr(attrs, LUCENE_MATCH_VERSION_PARAM);
|
||||
final Version luceneMatchVersion = (matchVersionStr == null) ?
|
||||
schema.getDefaultLuceneMatchVersion() :
|
||||
XmlConfigFile.parseLuceneVersionString(matchVersionStr);
|
||||
SolrConfig.parseLuceneVersionString(matchVersionStr);
|
||||
if (luceneMatchVersion == null) {
|
||||
throw new SolrException
|
||||
( SolrException.ErrorCode.SERVER_ERROR,
|
||||
|
@ -362,7 +362,7 @@ public final class FieldTypePluginLoader
|
|||
|
||||
private Version parseConfiguredVersion(String configuredVersion, String pluginClassName) {
|
||||
Version version = (configuredVersion != null) ?
|
||||
XmlConfigFile.parseLuceneVersionString(configuredVersion) : schema.getDefaultLuceneMatchVersion();
|
||||
SolrConfig.parseLuceneVersionString(configuredVersion) : schema.getDefaultLuceneMatchVersion();
|
||||
|
||||
if (!version.onOrAfter(Version.LUCENE_7_0_0)) {
|
||||
log.warn(pluginClassName + " is using deprecated " + version +
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.solr.analysis;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.core.XmlConfigFile;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.schema.FieldType;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
|
@ -37,7 +37,7 @@ public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
|
|||
|
||||
// this must match the solrconfig.xml version for this test
|
||||
public static final Version DEFAULT_VERSION =
|
||||
XmlConfigFile.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LATEST"));
|
||||
SolrConfig.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LATEST"));
|
||||
|
||||
public void testStandardTokenizerVersions() throws Exception {
|
||||
assertEquals(DEFAULT_VERSION, solrConfig.luceneMatchVersion);
|
||||
|
|
Loading…
Reference in New Issue