Skip to content

Apache Lucene open-source search software

SOLR-1677: Add more lenient support for version numbers (also 'V.V') format and add a system property for tests (set by build.xml), that specifies the current lucene version. TODO: Update all solrconfig.xml files to add the '3.1' luceneMatchVersion.

Uwe Schindler1f281686052f
diff --git a/build.xml b/build.xml
index 6076cdb9b5d..334061e66d1 100644
--- a/build.xml
+++ b/build.xml
@@ -35,6 +35,9 @@
<property name="clover.report.dir" location="${dest}/tests/clover/reports"/>
<property name="junit.details" value="1"/>
+
+ <!-- change this together with the default and test's solrconfig.xml after starting a new development branch: -->
+ <property name="tests.luceneMatchVersion" value="3.1"/>
<available
property="clover.present"
@@ -394,6 +397,7 @@
dir="src/test/test-files/"
>
<sysproperty key="java.util.logging.config.file" value="${common.dir}/testlogging.properties"/>
+ <sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<jvmarg line="${args}"/>
<formatter type="brief" usefile="false" if="junit.details"/>
<classpath refid="test.run.classpath"/>
diff --git a/src/java/org/apache/solr/core/Config.java b/src/java/org/apache/solr/core/Config.java
index f876168f852..8efae403c2e 100644
--- a/src/java/org/apache/solr/core/Config.java
+++ b/src/java/org/apache/solr/core/Config.java
@@ -284,16 +284,20 @@ public class Config {
private static final AtomicBoolean versionWarningAlreadyLogged = new AtomicBoolean(false);
- public static final Version parseLuceneVersionString(String matchVersion) {
- matchVersion = matchVersion.toUpperCase();
+ public static final Version parseLuceneVersionString(final String matchVersion) {
+ String parsedMatchVersion = matchVersion.toUpperCase();
+
+ // be lenient with the supplied version parameter
+ parsedMatchVersion = parsedMatchVersion.replaceFirst("^(\\d)\\.(\\d)$", "LUCENE_$1$2");
final Version version;
try {
- version = Version.valueOf(matchVersion);
+ version = Version.valueOf(parsedMatchVersion);
} catch (IllegalArgumentException iae) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Invalid luceneMatchVersion '" + matchVersion +
- "' property, valid values are: " + Arrays.toString(Version.values()), iae, false);
+ "', valid values are: " + Arrays.toString(Version.values()) +
+ " or a string in format 'V.V'", iae, false);
}
if (version == Version.LUCENE_CURRENT && !versionWarningAlreadyLogged.getAndSet(true)) {
diff --git a/src/test/org/apache/solr/analysis/BaseTokenTestCase.java b/src/test/org/apache/solr/analysis/BaseTokenTestCase.java
index 0bd6e209b3e..ec492e8a529 100644
--- a/src/test/org/apache/solr/analysis/BaseTokenTestCase.java
+++ b/src/test/org/apache/solr/analysis/BaseTokenTestCase.java
@@ -37,7 +37,7 @@ import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
public abstract class BaseTokenTestCase extends TestCase
{
protected static final Map<String,String> DEFAULT_VERSION_PARAM =
- Collections.singletonMap("luceneMatchVersion", "LUCENE_30");
+ Collections.singletonMap("luceneMatchVersion", System.getProperty("tests.luceneMatchVersion", "LUCENE_CURRENT"));
// some helpers to test Analyzers and TokenStreams:
// these are taken from Lucene's BaseTokenStreamTestCase
diff --git a/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java b/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
index d8be38d9b0e..f21a9295eff 100644
--- a/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
+++ b/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
@@ -20,6 +20,7 @@ import java.io.StringReader;
import java.lang.reflect.Field;
import org.apache.lucene.analysis.standard.StandardTokenizer;
+import org.apache.solr.core.Config;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.FieldType;
import org.apache.solr.util.AbstractSolrTestCase;
@@ -42,7 +43,9 @@ public class TestLuceneMatchVersion extends AbstractSolrTestCase {
return "solrconfig.xml";
}
- public static final Version DEFAULT_VERSION = Version.LUCENE_30;
+ // this must match the solrconfig.xml version for this test
+ public static final Version DEFAULT_VERSION =
+ Config.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LUCENE_CURRENT"));
public void testStandardTokenizerVersions() throws Exception {
assertEquals(DEFAULT_VERSION, solrConfig.luceneMatchVersion);
diff --git a/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml b/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml
index 1feb665ebc5..bbd9948bb75 100644
--- a/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml
+++ b/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml
@@ -22,7 +22,7 @@
<tokenizer class="solr.StandardTokenizerFactory" luceneMatchVersion="LUCENE_20"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
- <filter class="solr.StopFilterFactory" luceneMatchVersion="LUCENE_24"/>
+ <filter class="solr.StopFilterFactory" luceneMatchVersion="2.4"/>
<filter class="solr.EnglishPorterFilterFactory"/>
</analyzer>
</fieldtype>
diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xml
index be061d12dd6..ab3dd110ce4 100644
--- a/src/test/test-files/solr/conf/solrconfig.xml
+++ b/src/test/test-files/solr/conf/solrconfig.xml
@@ -45,7 +45,7 @@
not be changed if replication is in use. -->
<dataDir>${solr.data.dir:./solr/data}</dataDir>
- <luceneMatchVersion>LUCENE_30</luceneMatchVersion>
+ <luceneMatchVersion>3.1</luceneMatchVersion>
<indexDefaults>
<!-- Values here affect all index writers and act as a default