lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r800966 - in /lucene/solr/trunk/src/java/org/apache/solr/schema: ByteField.java DoubleField.java IntField.java LongField.java ShortField.java
Date Tue, 04 Aug 2009 20:51:13 GMT
Author: yonik
Date: Tue Aug  4 20:51:12 2009
New Revision: 800966

URL: http://svn.apache.org/viewvc?rev=800966&view=rev
Log:
SOLR-1270: make sure that plain numeric types produce correct transfer syntax for JSON, Python,
Ruby, and other TextWriter fields

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/IntField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java
    lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java?rev=800966&r1=800965&r2=800966&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java Tue Aug  4 20:51:12 2009
@@ -28,7 +28,7 @@
 import java.util.Map;
 
 /**
- * @version $Id: LongField.java 555343 2007-07-11 17:46:25Z hossman $
+ * @version $Id:$
  */
 public class ByteField extends FieldType {
   protected void init(IndexSchema schema, Map<String, String> args) {
@@ -50,7 +50,27 @@
   }
 
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
{
-    writer.writeByte(name, f.stringValue());
+    String s = f.stringValue();
+
+    // these values may be from a legacy lucene index, which may
+    // not be properly formatted in some output formats, or may
+    // incorrectly have a zero length.
+
+    if (s.length()==0) {
+      // zero length value means someone mistakenly indexed the value
+      // instead of simply leaving it out.  Write a null value instead of a numeric.
+      writer.writeNull(name);
+      return;
+    }
+
+    try {
+      byte val = Byte.parseByte(s);
+      writer.writeByte(name, val);
+    } catch (NumberFormatException e){
+      // can't parse - write out the contents as a string so nothing is lost and
+      // clients don't get a parse error.
+      writer.writeStr(name, s, true);
+    }
   }
 
   @Override

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java?rev=800966&r1=800965&r2=800966&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/DoubleField.java Tue Aug  4 20:51:12
2009
@@ -50,7 +50,27 @@
   }
 
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
{
-    writer.writeDouble(name, f.stringValue());
+    String s = f.stringValue();
+
+    // these values may be from a legacy lucene index, which may
+    // not be properly formatted in some output formats, or may
+    // incorrectly have a zero length.
+
+    if (s.length()==0) {
+      // zero length value means someone mistakenly indexed the value
+      // instead of simply leaving it out.  Write a null value instead of a numeric.
+      writer.writeNull(name);
+      return;
+    }
+
+    try {
+      double val = Double.parseDouble(s);
+      writer.writeDouble(name, val);
+    } catch (NumberFormatException e){
+      // can't parse - write out the contents as a string so nothing is lost and
+      // clients don't get a parse error.
+      writer.writeStr(name, s, true);
+    }
   }
 
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/IntField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/IntField.java?rev=800966&r1=800965&r2=800966&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/IntField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/IntField.java Tue Aug  4 20:51:12 2009
@@ -48,22 +48,26 @@
 
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
{
     String s = f.stringValue();
-    int len = s.length();
-    // these values may be from a legacy lucene index, which may contain
-    // integer values padded with zeros, or a zero length value.
-    if (len>=2) {
-      char ch = s.charAt(0);
-      if ((ch=='0') || (ch=='-' && s.charAt(1)=='0')) {
-        s = Integer.toString(Integer.parseInt(s));
-      }
-    } else if (len == 0) {
+
+    // these values may be from a legacy lucene index, which may
+    // not be properly formatted in some output formats, or may
+    // incorrectly have a zero length.
+
+    if (s.length()==0) {
       // zero length value means someone mistakenly indexed the value
-      // instead of simply leaving it out.  Write a null value instead
-      // of an integer value in this case.
+      // instead of simply leaving it out.  Write a null value instead of a numeric.
       writer.writeNull(name);
       return;
     }
-    writer.writeInt(name, s);
+
+    try {
+      int val = Integer.parseInt(s);
+      writer.writeInt(name, val);
+    } catch (NumberFormatException e){
+      // can't parse - write out the contents as a string so nothing is lost and
+      // clients don't get a parse error.
+      writer.writeStr(name, s, true);
+    }
   }
 
   @Override

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java?rev=800966&r1=800965&r2=800966&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/LongField.java Tue Aug  4 20:51:12 2009
@@ -55,22 +55,26 @@
   @Override
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
{
     String s = f.stringValue();
-    int len = s.length();
-    // these values may be from a legacy lucene index, which may contain
-    // integer values padded with zeros, or a zero length value.
-    if (len>=2) {
-      char ch = s.charAt(0);
-      if ((ch=='0') || (ch=='-' && s.charAt(1)=='0')) {
-        s = Long.toString(Long.parseLong(s));
-      }
-    } else if (len == 0) {
+
+    // these values may be from a legacy lucene index, which may
+    // not be properly formatted in some output formats, or may
+    // incorrectly have a zero length.
+
+    if (s.length()==0) {
       // zero length value means someone mistakenly indexed the value
-      // instead of simply leaving it out.  Write a null value instead
-      // of an integer value in this case.
+      // instead of simply leaving it out.  Write a null value instead of a numeric.
       writer.writeNull(name);
       return;
     }
-    writer.writeLong(name, s);
+
+    try {
+      long val = Long.parseLong(s);
+      writer.writeLong(name, val);
+    } catch (NumberFormatException e){
+      // can't parse - write out the contents as a string so nothing is lost and
+      // clients don't get a parse error.
+      writer.writeStr(name, s, true);
+    }
   }
 
   @Override

Modified: lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java?rev=800966&r1=800965&r2=800966&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java Tue Aug  4 20:51:12
2009
@@ -56,7 +56,27 @@
 
   @Override
   public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException
{
-    writer.writeShort(name, f.stringValue());
+    String s = f.stringValue();
+
+    // these values may be from a legacy lucene index, which may
+    // not be properly formatted in some output formats, or may
+    // incorrectly have a zero length.
+
+    if (s.length()==0) {
+      // zero length value means someone mistakenly indexed the value
+      // instead of simply leaving it out.  Write a null value instead of a numeric.
+      writer.writeNull(name);
+      return;
+    }
+
+    try {
+      short val = Short.parseShort(s);
+      writer.writeShort(name, val);
+    } catch (NumberFormatException e){
+      // can't parse - write out the contents as a string so nothing is lost and
+      // clients don't get a parse error.
+      writer.writeStr(name, s, true);
+    }
   }
 
   @Override



Mime
View raw message