You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2011/12/17 15:53:36 UTC

svn commit: r1215503 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/schema/ExternalFileField.java test-files/solr/conf/bad-schema-external-filefield.xml test-files/solr/conf/schema11.xml test/org/apache/solr/schema/BadIndexSchemaTest.java

Author: erick
Date: Sat Dec 17 14:53:36 2011
New Revision: 1215503

URL: http://svn.apache.org/viewvc?rev=1215503&view=rev
Log:
Fixes for SOLR-2971, valType now optional for 
ExternalFileFields and, if present, types float, pfloat, tfloat 
all accepable.

Added:
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml
Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java
    lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema11.xml
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java?rev=1215503&r1=1215502&r2=1215503&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java Sat Dec 17 14:53:36 2011
@@ -34,7 +34,9 @@ import java.io.IOException;
  * <li>It's OK to have some documents without a keyField in the file (defVal is used as the default)</li>
  * <li>It's OK for a keyField value to point to multiple documents (no uniqueness requirement)</li>
  * </ul>
- * <code>valType</code> is a reference to another fieldType to define the value type of this field (must currently be FloatField (float))
+ * <code>valType</code> is a reference to another fieldType to define the value type of this field
+ * (must currently be TrieFloatField or FloatField (valType="pfloat|float|tfloat") if used).
+ * This parameter has never been implemented. As of Solr 3.6/4.0 it is optional and can be omitted.
  *
  * The format of the external file is simply newline separated keyFieldValue=floatValue.
  * <br/>Example:
@@ -60,18 +62,21 @@ public class ExternalFileField extends F
   private float defVal;
 
   @Override
-  protected void init(IndexSchema schema, Map<String,String> args) {
+  protected void init(IndexSchema schema, Map<String, String> args) {
     restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
-    String ftypeS = getArg("valType", args);
-    if (ftypeS!=null) {
+    // valType has never been used for anything except to throw an error, so make it optional since the
+    // code (see getValueSource) gives you a FileFloatSource.
+    String ftypeS = args.remove("valType");
+    if (ftypeS != null) {
       ftype = schema.getFieldTypes().get(ftypeS);
-      if (ftype==null || !(ftype instanceof FloatField)) {
-        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Only float (FloatField) is currently supported as external field type.  got " + ftypeS);
+      if (ftype != null && !(ftype instanceof FloatField) && !(ftype instanceof TrieFloatField)) {
+        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+            "Only float and pfloat (Trie|Float)Field are currently supported as external field type.  Got " + ftypeS);
       }
-    }   
+    }
     keyFieldName = args.remove("keyField");
     String defValS = args.remove("defVal");
-    defVal = defValS==null ? 0 : Float.parseFloat(defValS);
+    defVal = defValS == null ? 0 : Float.parseFloat(defValS);
     this.schema = schema;
   }
 

Added: lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml?rev=1215503&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml Sat Dec 17 14:53:36 2011
@@ -0,0 +1,27 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<schema name="bad-schema-external-filefield" version="1.0">
+  <types>
+    <fieldType name="tint" class="solr.TrieIntField" omitNorms="true" positionIncrementGap="0"/>
+
+    <fieldType name="eff_none" keyField="id" defVal="0"
+               stored="false" indexed="true"
+               class="solr.ExternalFileField" valType="tint"/>
+
+  </types>
+</schema>

Modified: lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema11.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema11.xml?rev=1215503&r1=1215502&r2=1215503&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema11.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/conf/schema11.xml Sat Dec 17 14:53:36 2011
@@ -267,6 +267,24 @@
 valued. -->
     <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
 
+     <!-- These should pass right through and insure that we can declare external field types -->
+    <fieldType name="pfloat" class="solr.FloatField" omitNorms="true"/>
+    <fieldType name="eff_float" keyField="id" defVal="0"
+               stored="false" indexed="true"
+               class="solr.ExternalFileField" valType="float"/>
+
+    <fieldType name="eff_tfloat" keyField="id" defVal="0"
+               stored="false" indexed="true"
+               class="solr.ExternalFileField" valType="tfloat"/>
+
+    <fieldType name="eff_pfloat" keyField="id" defVal="0"
+               stored="false" indexed="true"
+               class="solr.ExternalFileField" valType="pfloat"/>
+
+    <!-- Be sure that the valType can be optional Since valType has done nothing up until now, this is preferred -->
+    <fieldType name="eff_none" keyField="id" defVal="0"
+               stored="false" indexed="true"
+               class="solr.ExternalFileField"/>
 
  </types>
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java?rev=1215503&r1=1215502&r2=1215503&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java Sat Dec 17 14:53:36 2011
@@ -35,8 +35,10 @@ public class BadIndexSchemaTest extends 
     try {
       initCore( "solrconfig.xml", schema );
     } catch (SolrException e) {
-      // short circut out if we found what we expected
+      // short circuit out if we found what we expected
       if (-1 != e.getMessage().indexOf(errString)) return;
+      // Test the cause too in case the expected error is wrapped
+      if (-1 != e.getCause().getMessage().indexOf(errString)) return;
 
       // otherwise, rethrow it, possibly completley unrelated
       throw new SolrException
@@ -44,6 +46,7 @@ public class BadIndexSchemaTest extends 
          "Unexpected error, expected error matching: " + errString, e);
     } finally {
       SolrConfig.severeErrors.clear();
+      deleteCore();
     }
     fail("Did not encounter any exception from: " + schema);
   }
@@ -75,4 +78,10 @@ public class BadIndexSchemaTest extends 
   public void testSevereErrorsForUnexpectedAnalyzer() throws Exception {
     doTest("bad-schema-nontext-analyzer.xml", "StrField (bad_type)");
   }
+
+  @Test
+  public void testBadExternalFileField() throws Exception {
+    doTest("bad-schema-external-filefield.xml",
+        "Only float and pfloat");
+  }
 }