You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2011/07/25 00:46:44 UTC

svn commit: r1150510 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ solr/ solr/core/src/java/org/apache/solr/schema/ solr/core/src/test-files/solr/conf/ solr/core/src/te...

Author: hossman
Date: Sun Jul 24 22:46:43 2011
New Revision: 1150510

URL: http://svn.apache.org/viewvc?rev=1150510&view=rev
Log:
SOLR-2669: Fix backwards validation logic in SchemaField.calcProps

Added:
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xml
      - copied unchanged from r1150478, lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xml
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xml
      - copied unchanged from r1150478, lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xml
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xml
      - copied unchanged from r1150478, lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xml
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xml
      - copied unchanged from r1150478, lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xml
Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/SchemaField.java
    lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1150510&r1=1150509&r2=1150510&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Sun Jul 24 22:46:43 2011
@@ -32,6 +32,19 @@ Upgrading from Solr 3.3
   before the master.  If the master were to be updated first, the older
   searchers would not be able to read the new index format.
 
+* Previous versions of Solr silently allow and ignore some contradictory 
+  properties specified in schema.xml.  For example:
+    - indexed="false" omitNorms="false" 
+    - indexed="false" omitTermFreqAndPositions="false"
+  Field property validation has now been fixed, to ensure that
+  contradictions like these now generate error messages.  If users
+  have existing schemas that generate one of these new "conflicting
+  'false' field options for non-indexed field" error messages the
+  conflicting "omit*" properties can safely be removed, or changed to
+  "true" for consistent behavior with previous Solr versions.  This
+  situation has now been fixed to cause an error on startup when these
+  contradictory options.  See SOLR-2669.
+
 New Features
 ----------------------
 
@@ -122,6 +135,8 @@ Bug Fixes
   "start" parameter was not honored and the documents returned were
    0 through start+offset.  (Markus Jelsma, yonik)
 
+* SOLR-2669: Fix backwards validation of field properties in 
+  SchemaField.calcProps (hossman)
 
 
  Other Changes

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/IndexSchema.java?rev=1150510&r1=1150509&r2=1150510&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/IndexSchema.java Sun Jul 24 22:46:43 2011
@@ -675,7 +675,7 @@ public final class IndexSchema {
     } catch(Exception e) {
       // unexpected exception...
       SolrConfig.severeErrors.add( e );
-      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Schema Parsing Failed",e,false);
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Schema Parsing Failed: " + e.getMessage(), e,false);
     }
 
     // create the field analyzers

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/SchemaField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/SchemaField.java?rev=1150510&r1=1150509&r2=1150510&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/SchemaField.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/schema/SchemaField.java Sun Jul 24 22:46:43 2011
@@ -233,20 +233,27 @@ public final class SchemaField extends F
     }
 
     if (on(falseProps,INDEXED)) {
-      int pp = (INDEXED | OMIT_NORMS | OMIT_TF_POSITIONS | OMIT_POSITIONS
+      int pp = (INDEXED 
               | STORE_TERMVECTORS | STORE_TERMPOSITIONS | STORE_TERMOFFSETS
               | SORT_MISSING_FIRST | SORT_MISSING_LAST);
       if (on(pp,trueProps)) {
-        throw new RuntimeException("SchemaField: " + name + " conflicting indexed field options:" + props);
+        throw new RuntimeException("SchemaField: " + name + " conflicting 'true' field options for non-indexed field:" + props);
+      }
+      p &= ~pp;
+    }
+    if (on(falseProps,INDEXED)) {
+      int pp = (OMIT_NORMS | OMIT_TF_POSITIONS | OMIT_POSITIONS);
+      if (on(pp,falseProps)) {
+        throw new RuntimeException("SchemaField: " + name + " conflicting 'false' field options for non-indexed field:" + props);
       }
       p &= ~pp;
 
     }
 
-    if (on(falseProps,OMIT_TF_POSITIONS)) {
+    if (on(trueProps,OMIT_TF_POSITIONS)) {
       int pp = (OMIT_POSITIONS | OMIT_TF_POSITIONS);
-      if (on(pp, trueProps)) {
-        throw new RuntimeException("SchemaField: " + name + " conflicting indexed field options:" + props);
+      if (on(pp, falseProps)) {
+        throw new RuntimeException("SchemaField: " + name + " conflicting tf and position field options:" + props);
       }
       p &= ~pp;
     }

Modified: lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml?rev=1150510&r1=1150509&r2=1150510&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/schema.xml Sun Jul 24 22:46:43 2011
@@ -454,6 +454,24 @@
    <field name="test_posofftv" type="text" termVectors="true"
      termPositions="true" termOffsets="true"/>
 
+   <!-- test valid combinations of indexed settings, 
+        see also BadIndexSchemaTest -->
+   <!-- indexed=false should not prevent omit___=true -->
+   <field name="pint_i_norm" type="pint" omitNorms="true"
+          indexed="false" />
+   <field name="pint_i_tf"   type="pint" omitOmitTermFreqAndPositions="true"
+          indexed="false" />
+   <field name="pint_i_pos"  type="pint" omitPositions="true"
+          indexed="false" />
+   <field name="pint_i_all"  type="pint" 
+          indexed="false" 
+          omitNorms="true"
+          omitOmitTermFreqAndPositions="true"
+          omitPositions="true" />
+   <!-- omitOmitTermFreqAndPositions=false and omitPositions=true are ok -->
+   <field name="pint_tf_pos" type="pint" indexed="true" 
+          omitOmitTermFreqAndPositions="false" omitPositions="true" />
+
    <!-- test highlit field settings -->
    <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
    <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>

Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java?rev=1150510&r1=1150509&r2=1150510&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java Sun Jul 24 22:46:43 2011
@@ -21,37 +21,44 @@ import java.util.regex.Pattern;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.core.SolrConfig;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.util.AbstractSolrTestCase;
-
 
+import org.junit.Test;
 
 /**
  */
-public class BadIndexSchemaTest extends AbstractSolrTestCase {
-
-  private static final String bad_type = "StrField (bad_type)";
-
-  @Override public String getSchemaFile() { return "bad-schema.xml"; }
-  @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
+public class BadIndexSchemaTest extends SolrTestCaseJ4 {
 
-  @Override 
-  public void setUp() throws Exception {
-    ignoreException("_twice");
-    ignoreException("ftAgain");
-    ignoreException("fAgain");
-    ignoreException(Pattern.quote(bad_type));
+  private void doTest(final String schema, final String errString) 
+    throws Exception {
 
-    super.setUp();
-  }
-  
-  @Override 
-  public void tearDown() throws Exception {
-    SolrConfig.severeErrors.clear();
-    super.tearDown();
+    ignoreException(Pattern.quote(errString));
+    try {
+      initCore( "solrconfig.xml", schema );
+    } catch (SolrException e) {
+      // short circut out if we found what we expected
+      if (-1 != e.getMessage().indexOf(errString)) return;
+
+      // otherwise, rethrow it, possibly completley unrelated
+      throw new SolrException
+        (ErrorCode.SERVER_ERROR, 
+         "Unexpected error, expected error matching: " + errString, e);
+    } finally {
+      SolrConfig.severeErrors.clear();
+    }
+    fail("Did not encounter any exception from: " + schema);
   }
 
+  @Test
+  public void testSevereErrorsForInvalidFieldOptions() throws Exception {
+    doTest("bad-schema-not-indexed-but-norms.xml", "bad_field");
+    doTest("bad-schema-not-indexed-but-tf.xml", "bad_field");
+    doTest("bad-schema-not-indexed-but-pos.xml", "bad_field");
+    doTest("bad-schema-omit-tf-but-not-pos.xml", "bad_field");
+  }
   
   private Throwable findErrorWithSubstring( List<Throwable> err, String v )
   {
@@ -63,38 +70,45 @@ public class BadIndexSchemaTest extends 
     return null;
   }
   
-  
-  public void testSevereErrors() 
-  {
-    SolrCore core = h.getCore();
-    IndexSchema schema = core.getSchema();
-
-    for( Throwable t : SolrConfig.severeErrors ) {
-      log.info( "got ex:"+t.getMessage() );
-    }
-    
-    assertEquals( 4, SolrConfig.severeErrors.size() );
-
-    List<Throwable> err = new LinkedList<Throwable>();
-    err.addAll( SolrConfig.severeErrors );
-    
-    Throwable t = findErrorWithSubstring( err, "*_twice" );
-    assertNotNull( t );
-    err.remove( t );
-    
-    t = findErrorWithSubstring( err, "ftAgain" );
-    assertNotNull( t );
-    err.remove( t );
+  public void testSevereErrors() throws Exception {
+    final String bad_type = "StrField (bad_type)";
+    try {
+      initCore( "solrconfig.xml", "bad-schema.xml" );
+      
+      ignoreException("_twice");
+      ignoreException("ftAgain");
+      ignoreException("fAgain");
+      ignoreException(Pattern.quote(bad_type));
+      
+      for( Throwable t : SolrConfig.severeErrors ) {
+        log.info( "got ex:"+t.getMessage() );
+      }
     
-    t = findErrorWithSubstring( err, "fAgain" );
-    assertNotNull( t );
-    err.remove( t );
-
-    t = findErrorWithSubstring( err, bad_type );
-    assertNotNull( t );
-    err.remove( t );
+      assertEquals( 4, SolrConfig.severeErrors.size() );
 
-    // make sure thats all of them
-    assertTrue( err.isEmpty() );
+      List<Throwable> err = new LinkedList<Throwable>();
+      err.addAll( SolrConfig.severeErrors );
+      
+      Throwable t = findErrorWithSubstring( err, "*_twice" );
+      assertNotNull( t );
+      err.remove( t );
+      
+      t = findErrorWithSubstring( err, "ftAgain" );
+      assertNotNull( t );
+      err.remove( t );
+      
+      t = findErrorWithSubstring( err, "fAgain" );
+      assertNotNull( t );
+      err.remove( t );
+      
+      t = findErrorWithSubstring( err, bad_type );
+      assertNotNull( t );
+      err.remove( t );
+
+      // make sure thats all of them
+      assertTrue( err.isEmpty() );
+    } finally {
+      SolrConfig.severeErrors.clear();
+    }
   }
 }