lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1624089 - in /lucene/dev/trunk: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/ lucene/core/src/test/org/apache/lucene/util/ solr/ solr/core/ solr/core/src/java/org/apache/solr/core/ solr/core/src/java/org/apache/solr/...
Date Wed, 10 Sep 2014 18:21:17 GMT
Author: uschindler
Date: Wed Sep 10 18:21:16 2014
New Revision: 1624089

URL: http://svn.apache.org/r1624089
Log:
Merged revision(s) 1624073 from lucene/dev/branches/branch_4x:
LUCENE-5934: Fix backwards compatibility for 4.0 indexes.

Modified:
    lucene/dev/trunk/   (props changed)
    lucene/dev/trunk/lucene/   (props changed)
    lucene/dev/trunk/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/trunk/lucene/core/   (props changed)
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Version.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
    lucene/dev/trunk/solr/   (props changed)
    lucene/dev/trunk/solr/core/   (props changed)
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrConfig.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Wed Sep 10 18:21:16 2014
@@ -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

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Version.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Version.java?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Version.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/Version.java Wed Sep 10 18:21:16
2014
@@ -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;

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java Wed Sep
10 18:21:16 2014
@@ -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 LuceneT
     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 LuceneT
     } 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 LuceneT
   
   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 LuceneT
         }
       }
     }
+    assertTrue(atLeastOne);
   }
 
   public void testLatestVersionCommonBuild() {

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrConfig.java?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrConfig.java Wed Sep 10 18:21:16
2014
@@ -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

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
Wed Sep 10 18:21:16 2014
@@ -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");

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java?rev=1624089&r1=1624088&r2=1624089&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
Wed Sep 10 18:21:16 2014
@@ -51,7 +51,7 @@ public class TestLuceneMatchVersion exte
 
     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 exte
     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());
   }
 }



Mime
View raw message