mirror of https://github.com/apache/lucene.git
SOLR-1270: make sure that plain numeric types produce correct transfer syntax for JSON, Python, Ruby, and other TextWriter fields
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@800966 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f939400f13
commit
e918778c48
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version $Id: LongField.java 555343 2007-07-11 17:46:25Z hossman $
|
* @version $Id:$
|
||||||
*/
|
*/
|
||||||
public class ByteField extends FieldType {
|
public class ByteField extends FieldType {
|
||||||
protected void init(IndexSchema schema, Map<String, String> args) {
|
protected void init(IndexSchema schema, Map<String, String> args) {
|
||||||
|
@ -50,7 +50,27 @@ public class ByteField extends FieldType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
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
|
@Override
|
||||||
|
|
|
@ -50,7 +50,27 @@ public class DoubleField extends FieldType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,22 +48,26 @@ public class IntField extends FieldType {
|
||||||
|
|
||||||
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
||||||
String s = f.stringValue();
|
String s = f.stringValue();
|
||||||
int len = s.length();
|
|
||||||
// these values may be from a legacy lucene index, which may contain
|
// these values may be from a legacy lucene index, which may
|
||||||
// integer values padded with zeros, or a zero length value.
|
// not be properly formatted in some output formats, or may
|
||||||
if (len>=2) {
|
// incorrectly have a zero length.
|
||||||
char ch = s.charAt(0);
|
|
||||||
if ((ch=='0') || (ch=='-' && s.charAt(1)=='0')) {
|
if (s.length()==0) {
|
||||||
s = Integer.toString(Integer.parseInt(s));
|
|
||||||
}
|
|
||||||
} else if (len == 0) {
|
|
||||||
// zero length value means someone mistakenly indexed the value
|
// zero length value means someone mistakenly indexed the value
|
||||||
// instead of simply leaving it out. Write a null value instead
|
// instead of simply leaving it out. Write a null value instead of a numeric.
|
||||||
// of an integer value in this case.
|
|
||||||
writer.writeNull(name);
|
writer.writeNull(name);
|
||||||
return;
|
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
|
@Override
|
||||||
|
|
|
@ -55,22 +55,26 @@ public class LongField extends FieldType {
|
||||||
@Override
|
@Override
|
||||||
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
||||||
String s = f.stringValue();
|
String s = f.stringValue();
|
||||||
int len = s.length();
|
|
||||||
// these values may be from a legacy lucene index, which may contain
|
// these values may be from a legacy lucene index, which may
|
||||||
// integer values padded with zeros, or a zero length value.
|
// not be properly formatted in some output formats, or may
|
||||||
if (len>=2) {
|
// incorrectly have a zero length.
|
||||||
char ch = s.charAt(0);
|
|
||||||
if ((ch=='0') || (ch=='-' && s.charAt(1)=='0')) {
|
if (s.length()==0) {
|
||||||
s = Long.toString(Long.parseLong(s));
|
|
||||||
}
|
|
||||||
} else if (len == 0) {
|
|
||||||
// zero length value means someone mistakenly indexed the value
|
// zero length value means someone mistakenly indexed the value
|
||||||
// instead of simply leaving it out. Write a null value instead
|
// instead of simply leaving it out. Write a null value instead of a numeric.
|
||||||
// of an integer value in this case.
|
|
||||||
writer.writeNull(name);
|
writer.writeNull(name);
|
||||||
return;
|
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
|
@Override
|
||||||
|
|
|
@ -56,7 +56,27 @@ public class ShortField extends FieldType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue