lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1082638 - in /lucene/dev/trunk/solr: ./ src/java/org/apache/solr/schema/ src/java/org/apache/solr/update/
Date Thu, 17 Mar 2011 18:53:48 GMT
Author: ryan
Date: Thu Mar 17 18:53:48 2011
New Revision: 1082638

URL: http://svn.apache.org/viewvc?rev=1082638&view=rev
Log:
SOLR-2423: FieldType argument changed from String to Object Conversion from SolrInputDocument
> Object > Fieldable is now managed by FieldType rather then DocumentBuilder.


Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/BinaryField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/FieldType.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/PointType.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SchemaField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieDateField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/update/DocumentBuilder.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Mar 17 18:53:48 2011
@@ -189,6 +189,10 @@ Other Changes
   in the XMLResponseWriter was removed.  XMLResponseWriter only 
   no longer work with values less then 2.2 (ryan)
 
+* SOLR-2423: FieldType argument changed from String to Object
+  Conversion from SolrInputDocument > Object > Fieldable is now managed
+  by FieldType rather then DocumentBuilder.  (ryan)
+
 
 Documentation
 ----------------------

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/BinaryField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/BinaryField.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/BinaryField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/BinaryField.java Thu Mar 17 18:53:48
2011
@@ -54,6 +54,7 @@ public class BinaryField extends FieldTy
     return  ByteBuffer.wrap(f.getBinaryValue(), f.getBinaryOffset(), f.getBinaryLength()
) ;
   }
 
+  @Override
   public Fieldable createField(SchemaField field, Object val, float boost) {
     if (val == null) return null;
     if (!field.stored()) {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/FieldType.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/FieldType.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/FieldType.java Thu Mar 17 18:53:48
2011
@@ -223,17 +223,18 @@ public abstract class FieldType extends 
    *
    *
    */
-  public Fieldable createField(SchemaField field, String externalVal, float boost) {
+  public Fieldable createField(SchemaField field, Object value, float boost) {
     if (!field.indexed() && !field.stored()) {
       if (log.isTraceEnabled())
         log.trace("Ignoring unindexed/unstored field: " + field);
       return null;
     }
+    
     String val;
     try {
-      val = toInternal(externalVal);
+      val = toInternal(value.toString());
     } catch (RuntimeException e) {
-      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error while creating
field '" + field + "' from value '" + externalVal + "'", e, false);
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error while creating
field '" + field + "' from value '" + value + "'", e, false);
     }
     if (val==null) return null;
 
@@ -276,11 +277,11 @@ public abstract class FieldType extends 
    * @param boost The boost to apply
    * @return An array of {@link org.apache.lucene.document.Fieldable}
    *
-   * @see #createField(SchemaField, String, float)
+   * @see #createField(SchemaField, Object, float)
    * @see #isPolyField()
    */
-  public Fieldable[] createFields(SchemaField field, String externalVal, float boost) {
-    Fieldable f = createField( field, externalVal, boost);
+  public Fieldable[] createFields(SchemaField field, Object value, float boost) {
+    Fieldable f = createField( field, value, boost);
     return f==null ? new Fieldable[]{} : new Fieldable[]{f};
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/LatLonType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/LatLonType.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/LatLonType.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/LatLonType.java Thu Mar 17 18:53:48
2011
@@ -54,7 +54,8 @@ public class LatLonType extends Abstract
   }
 
   @Override
-  public Fieldable[] createFields(SchemaField field, String externalVal, float boost) {
+  public Fieldable[] createFields(SchemaField field, Object value, float boost) {
+    String externalVal = value.toString();
     //we could have tileDiff + 3 fields (two for the lat/lon, one for storage)
     Fieldable[] f = new Fieldable[(field.indexed() ? 2 : 0) + (field.stored() ? 1 : 0)];
     if (field.indexed()) {
@@ -280,7 +281,7 @@ public class LatLonType extends Abstract
   //It never makes sense to create a single field, so make it impossible to happen
 
   @Override
-  public Fieldable createField(SchemaField field, String externalVal, float boost) {
+  public Fieldable createField(SchemaField field, Object value, float boost) {
     throw new UnsupportedOperationException("LatLonType uses multiple fields.  field=" +
field.getName());
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/PointType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/PointType.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/PointType.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/PointType.java Thu Mar 17 18:53:48
2011
@@ -68,7 +68,8 @@ public class PointType extends Coordinat
   }
 
   @Override
-  public Fieldable[] createFields(SchemaField field, String externalVal, float boost) {
+  public Fieldable[] createFields(SchemaField field, Object value, float boost) {
+    String externalVal = value.toString();
     String[] point = new String[0];
     try {
       point = DistanceUtils.parsePoint(null, externalVal, dimension);
@@ -112,7 +113,7 @@ public class PointType extends Coordinat
    *
    */
   @Override
-  public Fieldable createField(SchemaField field, String externalVal, float boost) {
+  public Fieldable createField(SchemaField field, Object value, float boost) {
     throw new UnsupportedOperationException("PointType uses multiple fields.  field=" + field.getName());
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SchemaField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SchemaField.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SchemaField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SchemaField.java Thu Mar 17 18:53:48
2011
@@ -93,11 +93,11 @@ public final class SchemaField extends F
   boolean isBinary() { return (properties & BINARY)!=0; }
 
 
-  public Fieldable createField(String val, float boost) {
+  public Fieldable createField(Object val, float boost) {
     return type.createField(this,val,boost);
   }
   
-  public Fieldable[] createFields(String val, float boost) {
+  public Fieldable[] createFields(Object val, float boost) {
     return type.createFields(this,val,boost);
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieDateField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieDateField.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieDateField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieDateField.java Thu Mar 17 18:53:48
2011
@@ -168,7 +168,7 @@ public class TrieDateField extends DateF
   }
 
   @Override
-  public Fieldable createField(SchemaField field, String externalVal, float boost) {
+  public Fieldable createField(SchemaField field, Object value, float boost) {
     boolean indexed = field.indexed();
     boolean stored = field.stored();
 
@@ -183,7 +183,10 @@ public class TrieDateField extends DateF
     byte[] arr=null;
     TokenStream ts=null;
 
-    long time = super.parseMath(null, externalVal).getTime();
+    long time = (value instanceof Date) 
+      ? ((Date)value).getTime() 
+      : super.parseMath(null, value.toString()).getTime();
+      
     if (stored) arr = TrieField.toArr(time);
     if (indexed) ts = new NumericTokenStream(ps).setLongValue(time);
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java Thu Mar 17 18:53:48
2011
@@ -482,7 +482,7 @@ public class TrieField extends FieldType
   }
 
   @Override
-  public Fieldable createField(SchemaField field, String externalVal, float boost) {
+  public Fieldable createField(SchemaField field, Object value, float boost) {
     boolean indexed = field.indexed();
     boolean stored = field.stored();
 
@@ -500,27 +500,37 @@ public class TrieField extends FieldType
 
     switch (type) {
       case INTEGER:
-        int i = Integer.parseInt(externalVal);
+        int i = (value instanceof Number)
+          ? ((Number)value).intValue()
+          : Integer.parseInt(value.toString());
         if (stored) arr = toArr(i);
         if (indexed) ts = new NumericTokenStream(ps).setIntValue(i);
         break;
       case FLOAT:
-        float f = Float.parseFloat(externalVal);
+        float f = (value instanceof Number)
+          ? ((Number)value).floatValue()
+          : Float.parseFloat(value.toString());
         if (stored) arr = toArr(f);
         if (indexed) ts = new NumericTokenStream(ps).setFloatValue(f);
         break;
       case LONG:
-        long l = Long.parseLong(externalVal);
+        long l = (value instanceof Number)
+          ? ((Number)value).longValue()
+          : Long.parseLong(value.toString());
         if (stored) arr = toArr(l);
         if (indexed) ts = new NumericTokenStream(ps).setLongValue(l);
         break;
       case DOUBLE:
-        double d = Double.parseDouble(externalVal);
+        double d = (value instanceof Number)
+          ? ((Number)value).doubleValue()
+          : Double.parseDouble(value.toString());
         if (stored) arr = toArr(d);
         if (indexed) ts = new NumericTokenStream(ps).setDoubleValue(d);
         break;
       case DATE:
-        long time = dateField.parseMath(null, externalVal).getTime();
+        long time = (value instanceof Date)
+          ? ((Date)value).getTime()
+          : dateField.parseMath(null, value.toString()).getTime();
         if (stored) arr = toArr(time);
         if (indexed) ts = new NumericTokenStream(ps).setLongValue(time);
         break;

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/update/DocumentBuilder.java?rev=1082638&r1=1082637&r2=1082638&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/update/DocumentBuilder.java Thu Mar 17
18:53:48 2011
@@ -194,7 +194,7 @@ public class DocumentBuilder {
   }
 
 
-  private static void addField(Document doc, SchemaField field, String val, float boost)
{
+  private static void addField(Document doc, SchemaField field, Object val, float boost)
{
     if (field.isPolyField()) {
       Fieldable[] farr = field.getType().createFields(field, val, boost);
       for (Fieldable f : farr) {
@@ -257,30 +257,10 @@ public class DocumentBuilder {
           if( v == null ) {
             continue;
           }
-          String val = null;
           hasField = true;
-          boolean isBinaryField = false;
-          if (sfield != null && sfield.getType() instanceof BinaryField) {
-            isBinaryField = true;
-            BinaryField binaryField = (BinaryField) sfield.getType();
-            Fieldable f = binaryField.createField(sfield,v,boost);
-            if(f != null){
-              out.add(f);
-            }
+          if (sfield != null) {
             used = true;
-          } else {
-            // TODO!!! HACK -- date conversion
-            if (sfield != null && v instanceof Date && sfield.getType() instanceof
DateField) {
-              DateField df = (DateField) sfield.getType();
-              val = df.toInternal((Date) v) + 'Z';
-            } else if (v != null) {
-              val = v.toString();
-            }
-  
-            if (sfield != null) {
-              used = true;
-              addField(out, sfield, val, boost);
-            }
+            addField(out, sfield, v, boost);
           }
   
           // Check if we should copy this field to any other fields.
@@ -292,21 +272,18 @@ public class DocumentBuilder {
             if (!destinationField.multiValued() && out.get(destinationField.getName())
!= null) {
               throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                       "ERROR: "+getID(doc, schema)+"multiple values encountered for non multiValued
copy field " +
-                              destinationField.getName() + ": " + val);
+                              destinationField.getName() + ": " + v);
             }
   
             used = true;
-            //Don't worry about poly fields here
-            Fieldable [] fields = null;
-            if (isBinaryField) {
-              if (destinationField.getType() instanceof BinaryField) {
-                BinaryField binaryField = (BinaryField) destinationField.getType();
-                //TODO: safe to assume that binary fields only create one?
-                fields = new Fieldable[]{binaryField.createField(destinationField, v, boost)};
-              }
-            } else {
-              fields = destinationField.createFields(cf.getLimitedValue(val), boost);
+            
+            // Perhaps trim the length of a copy field
+            Object val = v;
+            if( val instanceof String && cf.getMaxChars() > 0 ) {
+              val = cf.getLimitedValue((String)val);
             }
+            
+            Fieldable [] fields = destinationField.createFields(val, boost);
             if (fields != null) { // null fields are not added
               for (Fieldable f : fields) {
                 out.add(f);



Mime
View raw message