mirror of https://github.com/apache/lucene.git
Merged revision(s) 1624073 from lucene/dev/branches/branch_4x:
LUCENE-5934: Fix backwards compatibility for 4.0 indexes. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1624089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
92f5ad5ea3
commit
031fc7d167
|
@ -148,6 +148,9 @@ Bug Fixes
|
|||
* LUCENE-5922: DocValuesDocIdSet on 5.x and FieldCacheDocIdSet on 4.x
|
||||
are not cacheable. (Adrien Grand)
|
||||
|
||||
* LUCENE-5934: Fix backwards compatibility for 4.0 indexes.
|
||||
(Uwe Schindler, Robert Muir, Ryan Ernst)
|
||||
|
||||
Build
|
||||
|
||||
* LUCENE-5909: Smoke tester now has better command line parsing and
|
||||
|
|
|
@ -36,21 +36,21 @@ public final class Version {
|
|||
* @deprecated (5.0) Use latest
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Version LUCENE_4_0_0_ALPHA = new Version(4, 0, 0, 1);
|
||||
public static final Version LUCENE_4_0_0_ALPHA = new Version(4, 0, 0, 0);
|
||||
|
||||
/**
|
||||
* Match settings and bugs in Lucene's 4.0.0-BETA release.
|
||||
* @deprecated (5.0) Use latest
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Version LUCENE_4_0_0_BETA = new Version(4, 0, 0, 2);
|
||||
public static final Version LUCENE_4_0_0_BETA = new Version(4, 0, 0, 1);
|
||||
|
||||
/**
|
||||
* Match settings and bugs in Lucene's 4.0.0 release.
|
||||
* @deprecated (5.0) Use latest
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Version LUCENE_4_0_0 = new Version(4, 0, 0);
|
||||
public static final Version LUCENE_4_0_0 = new Version(4, 0, 0, 2);
|
||||
|
||||
/**
|
||||
* Match settings and bugs in Lucene's 4.1.0 release.
|
||||
|
@ -213,9 +213,9 @@ public final class Version {
|
|||
@Deprecated
|
||||
public static final Version LUCENE_CURRENT = LATEST;
|
||||
|
||||
/** @deprecated Bad naming of constant; use {@link #LUCENE_4_0_0} instead. */
|
||||
/** @deprecated Bad naming of constant; use {@link #LUCENE_4_0_0} instead (this constant actually points to {@link #LUCENE_4_0_0_ALPHA} to match whole 4.0 series). */
|
||||
@Deprecated
|
||||
public static final Version LUCENE_4_0 = LUCENE_4_0_0;
|
||||
public static final Version LUCENE_4_0 = LUCENE_4_0_0_ALPHA;
|
||||
|
||||
/** @deprecated Bad naming of constant; use {@link #LUCENE_4_1_0} instead. */
|
||||
@Deprecated
|
||||
|
@ -277,7 +277,7 @@ public final class Version {
|
|||
if (pieces.length > 3) {
|
||||
prerelease = Integer.parseInt(pieces[3]);
|
||||
if (prerelease == 0) {
|
||||
throw new IllegalArgumentException("Invalid value " + prerelease + " for prelrease of version " + version +", should be 1 or 2");
|
||||
throw new IllegalArgumentException("Invalid value " + prerelease + " for prerelease of version " + version +", should be 1 or 2");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,13 +290,24 @@ public final class Version {
|
|||
* or version numbers in the format {@code "x.y.z"}.
|
||||
*/
|
||||
public static Version parseLeniently(String version) {
|
||||
if (version.equals("LATEST") || version.equals("LUCENE_CURRENT")) return LATEST;
|
||||
final String parsedMatchVersion = version
|
||||
.toUpperCase(Locale.ROOT)
|
||||
.replaceFirst("^LUCENE_(\\d+)_(\\d+)_(\\d+)$", "$1.$2.$3")
|
||||
.replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2.0")
|
||||
.replaceFirst("^LUCENE_(\\d)(\\d)$", "$1.$2.0");
|
||||
return parse(parsedMatchVersion);
|
||||
version = version.toUpperCase(Locale.ROOT);
|
||||
switch (version) {
|
||||
case "LATEST":
|
||||
case "LUCENE_CURRENT":
|
||||
return LATEST;
|
||||
case "LUCENE_4_0_0":
|
||||
return LUCENE_4_0_0;
|
||||
case "LUCENE_4_0_0_ALPHA":
|
||||
return LUCENE_4_0_0_ALPHA;
|
||||
case "LUCENE_4_0_0_BETA":
|
||||
return LUCENE_4_0_0_BETA;
|
||||
default:
|
||||
version = version
|
||||
.replaceFirst("^LUCENE_(\\d+)_(\\d+)_(\\d+)$", "$1.$2.$3")
|
||||
.replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2.0")
|
||||
.replaceFirst("^LUCENE_(\\d)(\\d)$", "$1.$2.0");
|
||||
return parse(version);
|
||||
}
|
||||
}
|
||||
|
||||
// stores the version pieces, with most significant pieces in high bits
|
||||
|
@ -325,11 +336,6 @@ public final class Version {
|
|||
throw new IllegalArgumentException("Prerelease version only supported with major release");
|
||||
}
|
||||
|
||||
if (prerelease == 0) {
|
||||
// final release should sort after alpha/beta
|
||||
prerelease = 3;
|
||||
}
|
||||
|
||||
encodedValue = major << 18 | minor << 10 | bugfix << 2 | prerelease;
|
||||
}
|
||||
|
||||
|
@ -346,7 +352,7 @@ public final class Version {
|
|||
int minor = (encodedValue >>> 10) & 0xFF;
|
||||
int bugfix = (encodedValue >>> 2) & 0xFF;
|
||||
int prerelease = encodedValue & 0x3;
|
||||
if (prerelease == 3) { // ie unencoded value is 0
|
||||
if (prerelease == 0) {
|
||||
return "" + major + "." + minor + "." + bugfix;
|
||||
}
|
||||
return "" + major + "." + minor + "." + bugfix + "." + prerelease;
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.lucene.util;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class TestVersion extends LuceneTestCase {
|
||||
|
@ -42,17 +43,29 @@ public class TestVersion extends LuceneTestCase {
|
|||
assertEquals("4.2.0", Version.LUCENE_4_2_0.toString());
|
||||
assertEquals("4.2.0", Version.LUCENE_4_2.toString());
|
||||
assertEquals("4.2.1", Version.LUCENE_4_2_1.toString());
|
||||
assertEquals("4.0.0.1", Version.LUCENE_4_0_0_ALPHA.toString());
|
||||
assertEquals("4.0.0.2", Version.LUCENE_4_0_0_BETA.toString());
|
||||
assertEquals("4.0.0", Version.LUCENE_4_0_0_ALPHA.toString());
|
||||
assertEquals("4.0.0.1", Version.LUCENE_4_0_0_BETA.toString());
|
||||
assertEquals("4.0.0.2", Version.LUCENE_4_0_0.toString());
|
||||
}
|
||||
|
||||
public void testParseLeniently() {
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("4.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("4.0.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("LUCENE_40"));
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("LUCENE_4_0"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("LUCENE_49"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("LUCENE_4_9"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("LUCENE_4_9_0"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("lucene_49"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("Lucene_4_9"));
|
||||
assertEquals(Version.LUCENE_4_9_0, Version.parseLeniently("Lucene_4_9_0"));
|
||||
assertEquals(Version.LUCENE_4_10_0, Version.parseLeniently("LUCENE_4_10"));
|
||||
assertEquals(Version.LUCENE_4_10_0, Version.parseLeniently("LUCENE_4_10_0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("4.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("4.0.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("LUCENE_40"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("LUCENE_4_0"));
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("LUCENE_4_0_0"));
|
||||
assertEquals(Version.LATEST, Version.parseLeniently("LATEST"));
|
||||
assertEquals(Version.LATEST, Version.parseLeniently("latest"));
|
||||
assertEquals(Version.LATEST, Version.parseLeniently("LUCENE_CURRENT"));
|
||||
assertEquals(Version.LATEST, Version.parseLeniently("lucene_current"));
|
||||
}
|
||||
|
||||
public void testParseLenientlyExceptions() {
|
||||
|
@ -62,14 +75,41 @@ public class TestVersion extends LuceneTestCase {
|
|||
} catch (IllegalArgumentException iae) {
|
||||
// pass
|
||||
}
|
||||
try {
|
||||
Version.parseLeniently("LUCENE_410");
|
||||
fail();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// pass
|
||||
}
|
||||
try {
|
||||
Version.parseLeniently("LUCENE41");
|
||||
fail();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
public void testParseLenientlyOnAllConstants() throws Exception {
|
||||
boolean atLeastOne = false;
|
||||
for (Field field : Version.class.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) {
|
||||
atLeastOne = true;
|
||||
Version v = (Version)field.get(Version.class);
|
||||
assertEquals(v, Version.parseLeniently(v.toString()));
|
||||
assertEquals(v, Version.parseLeniently(field.getName()));
|
||||
assertEquals(v, Version.parseLeniently(field.getName().toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
}
|
||||
assertTrue(atLeastOne);
|
||||
}
|
||||
|
||||
public void testParse() {
|
||||
assertEquals(Version.LUCENE_5_0_0, Version.parse("5.0.0"));
|
||||
assertEquals(Version.LUCENE_4_1_0, Version.parse("4.1"));
|
||||
assertEquals(Version.LUCENE_4_1_0, Version.parseLeniently("4.1.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("4.0.0.1"));
|
||||
assertEquals(Version.LUCENE_4_0_0_BETA, Version.parseLeniently("4.0.0.2"));
|
||||
assertEquals(Version.LUCENE_4_1_0, Version.parse("4.1.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parse("4.0.0"));
|
||||
assertEquals(Version.LUCENE_4_0_0_BETA, Version.parse("4.0.0.1"));
|
||||
assertEquals(Version.LUCENE_4_0_0, Version.parse("4.0.0.2"));
|
||||
}
|
||||
|
||||
public void testForwardsCompatibility() {
|
||||
|
@ -166,8 +206,10 @@ public class TestVersion extends LuceneTestCase {
|
|||
|
||||
public void testDeprecations() throws Exception {
|
||||
// all but the latest version should be deprecated
|
||||
boolean atLeastOne = false;
|
||||
for (Field field : Version.class.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) {
|
||||
atLeastOne = true;
|
||||
Version v = (Version)field.get(Version.class);
|
||||
final boolean dep = field.isAnnotationPresent(Deprecated.class);
|
||||
if (v.equals(Version.LATEST) && field.getName().equals("LUCENE_CURRENT") == false) {
|
||||
|
@ -177,6 +219,7 @@ public class TestVersion extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
assertTrue(atLeastOne);
|
||||
}
|
||||
|
||||
public void testLatestVersionCommonBuild() {
|
||||
|
|
|
@ -173,7 +173,7 @@ public class SolrConfig extends Config {
|
|||
boolean hasDeprecatedIndexConfig = (getNode("indexDefaults", false) != null) || (getNode("mainIndex", false) != null);
|
||||
boolean hasNewIndexConfig = getNode("indexConfig", false) != null;
|
||||
if(hasDeprecatedIndexConfig){
|
||||
if(luceneMatchVersion.onOrAfter(Version.LUCENE_4_0_0)) {
|
||||
if(luceneMatchVersion.onOrAfter(Version.LUCENE_4_0_0_ALPHA)) {
|
||||
throw new SolrException(ErrorCode.FORBIDDEN, "<indexDefaults> and <mainIndex> configuration sections are discontinued. Use <indexConfig> instead.");
|
||||
} else {
|
||||
// Still allow the old sections for older LuceneMatchVersion's
|
||||
|
|
|
@ -398,7 +398,7 @@ public final class FieldTypePluginLoader
|
|||
Version version = (configuredVersion != null) ?
|
||||
Config.parseLuceneVersionString(configuredVersion) : schema.getDefaultLuceneMatchVersion();
|
||||
|
||||
if (!version.onOrAfter(Version.LUCENE_4_0_0)) {
|
||||
if (!version.onOrAfter(Version.LUCENE_4_0_0_ALPHA)) {
|
||||
log.warn(pluginClassName + " is using deprecated " + version +
|
||||
" emulation. You should at some point declare and reindex to at least 4.0, because " +
|
||||
"3.x emulation is deprecated and will be removed in 5.0");
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
|
|||
|
||||
type = schema.getFieldType("text40");
|
||||
ana = (TokenizerChain) type.getIndexAnalyzer();
|
||||
assertEquals(Version.LUCENE_4_0_0, (ana.getTokenizerFactory()).getLuceneMatchVersion());
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, (ana.getTokenizerFactory()).getLuceneMatchVersion());
|
||||
assertEquals(Version.LUCENE_5_0_0, (ana.getTokenFilterFactories()[2]).getLuceneMatchVersion());
|
||||
|
||||
type = schema.getFieldType("textTurkishAnalyzerDefault");
|
||||
|
@ -62,6 +62,6 @@ public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
|
|||
type = schema.getFieldType("textTurkishAnalyzer40");
|
||||
ana1 = type.getIndexAnalyzer();
|
||||
assertTrue(ana1 instanceof TurkishAnalyzer);
|
||||
assertEquals(Version.LUCENE_4_0_0, ana1.getVersion());
|
||||
assertEquals(Version.LUCENE_4_0_0_ALPHA, ana1.getVersion());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue