SOLR-2297: move XML response writing to TextResponseWriter framework

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1052540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-12-24 17:51:48 +00:00
parent 9b4e4a608e
commit ab0e9eab62
35 changed files with 214 additions and 670 deletions

View File

@ -266,7 +266,6 @@
sourcepath=""
classpathref="@{classpathref}">
<nested />
<compilerarg line="-Xlint -Xlint:-deprecation -Xlint:-serial"/>
</javac>
</sequential>
</macrodef>

View File

@ -474,10 +474,6 @@ class CSVWriter extends TextResponseWriter {
public void writeMap(String name, Map val, boolean excludeOuter, boolean isFirstVal) throws IOException {
}
@Override
public void writeArray(String name, Object[] val) throws IOException {
}
@Override
public void writeArray(String name, Iterator val) throws IOException {
}
@ -523,14 +519,4 @@ class CSVWriter extends TextResponseWriter {
public void writeDate(String name, String val) throws IOException {
printer.print(val, false);
}
@Override
public void writeShort(String name, String val) throws IOException {
printer.print(val, false);
}
@Override
public void writeByte(String name, String val) throws IOException {
printer.print(val, false);
}
}

View File

@ -63,10 +63,6 @@ public class JSONResponseWriter implements QueryResponseWriter {
class JSONWriter extends TextResponseWriter {
// cache the calendar instance in case we are writing many dates...
private Calendar cal;
private String namedListStyle;
private String wrapperFunction;
@ -682,10 +678,6 @@ class JSONWriter extends TextResponseWriter {
}
}
public void writeArray(String name, Object[] val) throws IOException {
writeArray(name, Arrays.asList(val).iterator());
}
public void writeArray(String name, Iterator val) throws IOException {
writeArrayOpener(-1); // no trivial way to determine array size
incLevel();
@ -729,73 +721,6 @@ class JSONWriter extends TextResponseWriter {
writer.write(val);
}
@Override
public void writeShort(String name, String val) throws IOException {
writer.write(val);
}
public void writeByte(String name, String val) throws IOException {
writer.write(val);
}
// TODO: refactor this out to a DateUtils class or something...
public void writeDate(String name, Date val) throws IOException {
// using a stringBuilder for numbers can be nice since
// a temporary string isn't used (it's added directly to the
// builder's buffer.
StringBuilder sb = new StringBuilder();
if (cal==null) cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
cal.setTime(val);
int i = cal.get(Calendar.YEAR);
sb.append(i);
sb.append('-');
i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
if (i<10) sb.append('0');
sb.append(i);
sb.append('-');
i=cal.get(Calendar.DAY_OF_MONTH);
if (i<10) sb.append('0');
sb.append(i);
sb.append('T');
i=cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.MINUTE);
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.SECOND);
if (i<10) sb.append('0');
sb.append(i);
i=cal.get(Calendar.MILLISECOND);
if (i != 0) {
sb.append('.');
if (i<100) sb.append('0');
if (i<10) sb.append('0');
sb.append(i);
// handle canonical format specifying fractional
// seconds shall not end in '0'. Given the slowness of
// integer div/mod, simply checking the last character
// is probably the fastest way to check.
int lastIdx = sb.length()-1;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
}
sb.setLength(lastIdx+1);
}
}
sb.append('Z');
writeDate(name, sb.toString());
}
public void writeDate(String name, String val) throws IOException {
writeStr(name, val, false);
}

View File

@ -28,10 +28,7 @@ import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.DocList;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.*;
/** Base class for text-oriented response writers.
*
@ -39,6 +36,14 @@ import java.util.Set;
*/
public abstract class TextResponseWriter {
// indent up to 40 spaces
static final char[] indentChars = new char[81];
static {
Arrays.fill(indentChars,' ');
indentChars[0] = '\n'; // start with a newline
}
protected final FastWriter writer;
protected final IndexSchema schema;
protected final SolrQueryRequest req;
@ -50,6 +55,8 @@ public abstract class TextResponseWriter {
protected int level;
protected boolean doIndent;
protected Calendar cal; // reusable calendar instance
public TextResponseWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
this.writer = FastWriter.wrap(writer);
@ -63,6 +70,8 @@ public abstract class TextResponseWriter {
returnFields = rsp.getReturnFields();
}
/** done with this ResponseWriter... make sure any buffers are flushed to writer */
public void close() throws IOException {
writer.flushBuffer();
@ -77,10 +86,9 @@ public abstract class TextResponseWriter {
}
public void indent(int lev) throws IOException {
writer.write(XMLWriter.indentChars, 0, Math.min((lev<<1)+1, XMLWriter.indentChars.length));
writer.write(indentChars, 0, Math.min((lev<<1)+1, indentChars.length));
}
//
// Functions to manipulate the current logical nesting level.
// Any indentation will be partially based on level.
@ -173,7 +181,9 @@ public abstract class TextResponseWriter {
public abstract void writeMap(String name, Map val, boolean excludeOuter, boolean isFirstVal) throws IOException;
public abstract void writeArray(String name, Object[] val) throws IOException;
public void writeArray(String name, Object[] val) throws IOException {
writeArray(name, Arrays.asList(val).iterator());
}
public abstract void writeArray(String name, Iterator val) throws IOException;
@ -228,20 +238,65 @@ public abstract class TextResponseWriter {
}
}
public abstract void writeDate(String name, Date val) throws IOException;
public void writeDate(String name, Date val) throws IOException {
// using a stringBuilder for numbers can be nice since
// a temporary string isn't used (it's added directly to the
// builder's buffer.
StringBuilder sb = new StringBuilder();
if (cal==null) cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
cal.setTime(val);
int i = cal.get(Calendar.YEAR);
sb.append(i);
sb.append('-');
i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
if (i<10) sb.append('0');
sb.append(i);
sb.append('-');
i=cal.get(Calendar.DAY_OF_MONTH);
if (i<10) sb.append('0');
sb.append(i);
sb.append('T');
i=cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.MINUTE);
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.SECOND);
if (i<10) sb.append('0');
sb.append(i);
i=cal.get(Calendar.MILLISECOND);
if (i != 0) {
sb.append('.');
if (i<100) sb.append('0');
if (i<10) sb.append('0');
sb.append(i);
// handle canonical format specifying fractional
// seconds shall not end in '0'. Given the slowness of
// integer div/mod, simply checking the last character
// is probably the fastest way to check.
int lastIdx = sb.length()-1;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
}
sb.setLength(lastIdx+1);
}
}
sb.append('Z');
writeDate(name, sb.toString());
}
/** if this form of the method is called, val is the Solr ISO8601 based date format */
public abstract void writeDate(String name, String val) throws IOException;
public abstract void writeShort(String name, String val) throws IOException;
public void writeShort(String name, short val) throws IOException{
writeShort(name, Short.toString(val));
}
public abstract void writeByte(String name, String s) throws IOException;
public void writeByte(String name, byte val) throws IOException{
writeByte(name, Byte.toString(val));
}
}

View File

@ -32,7 +32,12 @@ public class XMLResponseWriter implements QueryResponseWriter {
}
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
XMLWriter.writeResponse(writer,req,rsp);
XMLWriter w = new XMLWriter(writer, req, rsp);
try {
w.writeResponse();
} finally {
w.close();
}
}
public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {

View File

@ -37,34 +37,54 @@ import java.util.*;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.Document;
/**
* @version $Id$
*/
final public class XMLWriter {
public final class XMLWriter extends TextResponseWriter {
public static float CURRENT_VERSION=2.2f;
//
// static thread safe part
//
private static final char[] XML_START1="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".toCharArray();
private static final char[] XML_STYLESHEET="<?xml-stylesheet type=\"text/xsl\" href=\"/admin/".toCharArray();
private static final char[] XML_STYLESHEET_END=".xsl\"?>\n".toCharArray();
/***
private static final char[] XML_START2_SCHEMA=(
"<response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+" xsi:noNamespaceSchemaLocation=\"http://pi.cnet.com/cnet-search/response.xsd\">\n"
).toCharArray();
private static final char[] XML_START2_NOSCHEMA=(
"<response>\n"
).toCharArray();
***/
private static final char[] XML_START2_NOSCHEMA=("<response>\n").toCharArray();
private boolean defaultIndent=false;
final int version;
// temporary working objects...
// be careful not to use these recursively...
private final ArrayList tlst = new ArrayList();
public static void writeResponse(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
XMLWriter xmlWriter = null;
try {
xmlWriter = new XMLWriter(writer, req, rsp);
xmlWriter.writeResponse();
} finally {
xmlWriter.close();
}
}
String ver = req.getParams().get(CommonParams.VERSION);
public XMLWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
super(writer, req, rsp);
String version = req.getParams().get("version");
float ver = version==null? CURRENT_VERSION : Float.parseFloat(version);
this.version = (int)(ver*1000);
}
public void writeResponse() throws IOException {
writer.write(XML_START1);
String stylesheet = req.getParams().get("stylesheet");
@ -74,29 +94,15 @@ final public class XMLWriter {
writer.write(XML_STYLESHEET_END);
}
/***
String noSchema = req.getParams().get("noSchema");
// todo - change when schema becomes available?
if (false && noSchema == null)
writer.write(XML_START2_SCHEMA);
else
writer.write(XML_START2_NOSCHEMA);
// create an instance for each request to handle
// non-thread safe stuff (indentation levels, etc)
// and to encapsulate writer, schema, and searcher so
// they don't have to be passed around in every function.
//
XMLWriter xw = new XMLWriter(writer, req.getSchema(), req, ver);
xw.defaultFieldList = rsp.getReturnFields();
String indent = req.getParams().get("indent");
if (indent != null) {
if ("".equals(indent) || "off".equals(indent)) {
xw.setIndent(false);
} else {
xw.setIndent(true);
}
}
***/
writer.write(XML_START2_NOSCHEMA);
// dump response values
NamedList lst = rsp.getValues();
@ -106,89 +112,40 @@ final public class XMLWriter {
int start=0;
// special case the response header if the version is 2.1 or less
if (xw.version<=2100 && sz>0) {
if (version<=2100 && sz>0) {
Object header = lst.getVal(0);
if (header instanceof NamedList && "responseHeader".equals(lst.getName(0))) {
writer.write("<responseHeader>");
xw.incLevel();
incLevel();
NamedList nl = (NamedList)header;
for (int i=0; i<nl.size(); i++) {
String name = nl.getName(i);
Object val = nl.getVal(i);
if ("status".equals(name) || "QTime".equals(name)) {
xw.writePrim(name,null,val.toString(),false);
writePrim(name,null,val.toString(),false);
} else {
xw.writeVal(name,val);
writeVal(name,val);
}
}
xw.decLevel();
decLevel();
writer.write("</responseHeader>");
start=1;
}
}
for (int i=start; i<sz; i++) {
xw.writeVal(lst.getName(i),lst.getVal(i));
writeVal(lst.getName(i),lst.getVal(i));
}
writer.write("\n</response>\n");
}
////////////////////////////////////////////////////////////
// request instance specific (non-static, not shared between threads)
////////////////////////////////////////////////////////////
private final Writer writer;
private final IndexSchema schema; // needed to write fields of docs
private final SolrQueryRequest request; // the request
private int level;
private boolean defaultIndent=false;
private boolean doIndent=false;
// fieldList... the set of fields to return for each document
private Set<String> defaultFieldList;
// if a list smaller than this threshold is encountered, elements
// will be written on the same line.
// maybe constructed types should always indent first?
private final int indentThreshold=0;
final int version;
// temporary working objects...
// be careful not to use these recursively...
private final ArrayList tlst = new ArrayList();
private final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
private final StringBuilder sb = new StringBuilder();
public XMLWriter(Writer writer, IndexSchema schema, SolrQueryRequest req, String version) {
this.writer = writer;
this.schema = schema;
this.request = req;
float ver = version==null? CURRENT_VERSION : Float.parseFloat(version);
this.version = (int)(ver*1000);
}
//
// Functions to manipulate the current logical nesting level.
// Any indentation will be partially based on level.
//
public void setLevel(int level) { this.level = level; }
public int level() { return level; }
public int incLevel() { return ++level; }
public int decLevel() { return --level; }
public void setIndent(boolean doIndent) {
this.doIndent = doIndent;
defaultIndent = doIndent;
}
/** Writes the XML attribute name/val. A null val means that the attribute is missing. */
public void writeAttr(String name, String val) throws IOException {
private void writeAttr(String name, String val) throws IOException {
writeAttr(name, val, true);
}
@ -206,63 +163,7 @@ final public class XMLWriter {
}
}
/**Writes a tag with attributes
*
* @param tag
* @param attributes
* @param closeTag
* @param escape
* @throws IOException
*/
public void startTag(String tag, Map<String,String> attributes, boolean closeTag, boolean escape) throws IOException {
if (doIndent) indent();
writer.write('<');
writer.write(tag);
if(!attributes.isEmpty()) {
for (Map.Entry<String, String> entry : attributes.entrySet()) {
writeAttr(entry.getKey(), entry.getValue(), escape);
}
}
if (closeTag) {
writer.write("/>");
} else {
writer.write('>');
}
}
/**Write a complete tag w/ attributes and cdata (the cdata is not enclosed in $lt;!CDATA[]!&gt;
* @param tag
* @param attributes
* @param cdata
* @param escapeCdata
* @param escapeAttr
* @throws IOException
*/
public void writeCdataTag(String tag, Map<String,String> attributes, String cdata, boolean escapeCdata, boolean escapeAttr) throws IOException {
if (doIndent) indent();
writer.write('<');
writer.write(tag);
if (!attributes.isEmpty()) {
for (Map.Entry<String, String> entry : attributes.entrySet()) {
writeAttr(entry.getKey(), entry.getValue(), escapeAttr);
}
}
writer.write('>');
if (cdata != null && cdata.length() > 0) {
if (escapeCdata) {
XML.escapeCharData(cdata, writer);
} else {
writer.write(cdata, 0, cdata.length());
}
}
writer.write("</");
writer.write(tag);
writer.write('>');
}
public void startTag(String tag, String name, boolean closeTag) throws IOException {
void startTag(String tag, String name, boolean closeTag) throws IOException {
if (doIndent) indent();
writer.write('<');
@ -283,22 +184,6 @@ final public class XMLWriter {
}
}
// indent up to 40 spaces
static final char[] indentChars = new char[81];
static {
Arrays.fill(indentChars,' ');
indentChars[0] = '\n'; // start with a newline
}
public void indent() throws IOException {
indent(level);
}
public void indent(int lev) throws IOException {
writer.write(indentChars, 0, Math.min((lev<<1)+1, indentChars.length));
}
private static final Comparator fieldnameComparator = new Comparator() {
public int compare(Object o, Object o1) {
Fieldable f1 = (Fieldable)o; Fieldable f2 = (Fieldable)o1;
@ -309,6 +194,7 @@ final public class XMLWriter {
}
};
@Override
public final void writeDoc(String name, Document doc, Set<String> returnFields, float score, boolean includeScore) throws IOException {
startTag("doc", name, false);
incLevel();
@ -400,17 +286,11 @@ final public class XMLWriter {
writer.write("</doc>");
}
/**
* @since solr 1.3
*/
final void writeDoc(String name, SolrDocument doc, Set<String> returnFields, boolean includeScore) throws IOException {
@Override
public void writeSolrDocument(String name, SolrDocument doc, Set<String> returnFields, Map pseudoFields) throws IOException {
startTag("doc", name, false);
incLevel();
if (includeScore && returnFields != null ) {
returnFields.add( "score" );
}
for (String fname : doc.getFieldNames()) {
if (returnFields!=null && !returnFields.contains(fname)) {
continue;
@ -434,6 +314,12 @@ final public class XMLWriter {
}
}
if (pseudoFields != null) {
for (Object fname : pseudoFields.keySet()) {
writeVal(fname.toString(), pseudoFields.get(fname));
}
}
decLevel();
if (doIndent) indent();
writer.write("</doc>");
@ -466,8 +352,8 @@ final public class XMLWriter {
writer.write("<result");
writeAttr("name",name);
writeAttr("numFound",Long.toString(docs.getNumFound())); // TODO: change to long
writeAttr("start",Long.toString(docs.getStart())); // TODO: change to long
writeAttr("numFound",Long.toString(docs.getNumFound()));
writeAttr("start",Long.toString(docs.getStart()));
if (includeScore && docs.getMaxScore()!=null) {
writeAttr("maxScore",Float.toString(docs.getMaxScore()));
}
@ -486,7 +372,8 @@ final public class XMLWriter {
writer.write("</result>");
}
public final void writeSolrDocumentList(String name, final SolrDocumentList docs, Set<String> fields) throws IOException
@Override
public final void writeSolrDocumentList(String name, final SolrDocumentList docs, Set<String> fields, Map otherFields) throws IOException
{
this.writeDocuments( name, new DocumentListInfo()
{
@ -508,13 +395,14 @@ final public class XMLWriter {
public void writeDocs(boolean includeScore, Set<String> fields) throws IOException {
for( SolrDocument doc : docs ) {
writeDoc(null, doc, fields, includeScore);
writeSolrDocument(null, doc, fields, null);
}
}
}, fields );
}
public final void writeDocList(String name, final DocList ids, Set<String> fields) throws IOException
@Override
public void writeDocList(String name, final DocList ids, Set<String> fields, Map otherFields) throws IOException
{
this.writeDocuments( name, new DocumentListInfo()
{
@ -535,7 +423,7 @@ final public class XMLWriter {
}
public void writeDocs(boolean includeScore, Set<String> fields) throws IOException {
SolrIndexSearcher searcher = request.getSearcher();
SolrIndexSearcher searcher = req.getSearcher();
DocIterator iterator = ids.iterator();
int sz = ids.size();
includeScore = includeScore && ids.hasScores();
@ -558,7 +446,7 @@ final public class XMLWriter {
if (val==null) {
writeNull(name);
} else if (val instanceof String) {
writeStr(name, (String)val);
writeStr(name, (String)val, true);
} else if (val instanceof Integer) {
// it would be slower to pass the int ((Integer)val).intValue()
writeInt(name, val.toString());
@ -576,19 +464,19 @@ final public class XMLWriter {
} else if (val instanceof Double) {
writeDouble(name, ((Double)val).doubleValue());
} else if (val instanceof Document) {
writeDoc(name, (Document)val, defaultFieldList, 0.0f, false);
writeDoc(name, (Document)val, returnFields, 0.0f, false);
} else if (val instanceof DocList) {
// requires access to IndexReader
writeDocList(name, (DocList)val, defaultFieldList);
writeDocList(name, (DocList)val, returnFields, null);
}else if (val instanceof SolrDocumentList) {
// requires access to IndexReader
writeSolrDocumentList(name, (SolrDocumentList)val, defaultFieldList);
writeSolrDocumentList(name, (SolrDocumentList)val, returnFields, null);
}else if (val instanceof DocSet) {
// how do we know what fields to read?
// todo: have a DocList/DocSet wrapper that
// restricts the fields to write...?
} else if (val instanceof Map) {
writeMap(name, (Map)val);
writeMap(name, (Map)val, false, true);
} else if (val instanceof NamedList) {
writeNamedList(name, (NamedList)val);
} else if (val instanceof Iterable) {
@ -599,7 +487,7 @@ final public class XMLWriter {
writeArray(name,(Iterator)val);
} else {
// default...
writeStr(name, val.getClass().getName() + ':' + val.toString());
writeStr(name, val.getClass().getName() + ':' + val.toString(), true);
}
}
@ -611,10 +499,6 @@ final public class XMLWriter {
int sz = val.size();
startTag("lst", name, sz<=0);
if (sz<indentThreshold) {
doIndent=false;
}
incLevel();
for (int i=0; i<sz; i++) {
writeVal(val.getName(i),val.getVal(i));
@ -627,37 +511,37 @@ final public class XMLWriter {
}
}
/**
* writes a Map in the same format as a NamedList, using the
* stringification of the key Object when it's non-null.
*
* @param name
* @param map
* @throws IOException
* @see SolrQueryResponse Note on Returnable Data
*/
public void writeMap(String name, Map<Object,Object> map) throws IOException {
@Override
public void writeMap(String name, Map map, boolean excludeOuter, boolean isFirstVal) throws IOException {
int sz = map.size();
startTag("lst", name, sz<=0);
incLevel();
for (Map.Entry<Object,Object> entry : map.entrySet()) {
if (!excludeOuter) {
startTag("lst", name, sz<=0);
incLevel();
}
for (Map.Entry entry : (Set<Map.Entry>)map.entrySet()) {
Object k = entry.getKey();
Object v = entry.getValue();
// if (sz<indentThreshold) indent();
writeVal( null == k ? null : k.toString(), v);
}
decLevel();
if (sz > 0) {
if (doIndent) indent();
writer.write("</lst>");
if (!excludeOuter) {
decLevel();
if (sz > 0) {
if (doIndent) indent();
writer.write("</lst>");
}
}
}
@Override
public void writeArray(String name, Object[] val) throws IOException {
writeArray(name, Arrays.asList(val).iterator());
}
@Override
public void writeArray(String name, Iterator iter) throws IOException {
if( iter.hasNext() ) {
startTag("arr", name, false );
@ -678,127 +562,53 @@ final public class XMLWriter {
// Primitive types
//
@Override
public void writeNull(String name) throws IOException {
writePrim("null",name,"",false);
}
public void writeStr(String name, String val) throws IOException {
writePrim("str",name,val,true);
@Override
public void writeStr(String name, String val, boolean escape) throws IOException {
writePrim("str",name,val,escape);
}
@Override
public void writeInt(String name, String val) throws IOException {
writePrim("int",name,val,false);
}
public void writeInt(String name, int val) throws IOException {
writeInt(name,Integer.toString(val));
}
@Override
public void writeLong(String name, String val) throws IOException {
writePrim("long",name,val,false);
}
public void writeLong(String name, long val) throws IOException {
writeLong(name,Long.toString(val));
}
@Override
public void writeBool(String name, String val) throws IOException {
writePrim("bool",name,val,false);
}
public void writeBool(String name, boolean val) throws IOException {
writeBool(name,Boolean.toString(val));
}
public void writeShort(String name, String val) throws IOException {
writePrim("short",name,val,false);
}
public void writeShort(String name, short val) throws IOException {
writeInt(name,Short.toString(val));
}
public void writeByte(String name, String val) throws IOException {
writePrim("byte",name,val,false);
}
public void writeByte(String name, byte val) throws IOException {
writeInt(name,Byte.toString(val));
}
@Override
public void writeFloat(String name, String val) throws IOException {
writePrim("float",name,val,false);
}
@Override
public void writeFloat(String name, float val) throws IOException {
writeFloat(name,Float.toString(val));
}
@Override
public void writeDouble(String name, String val) throws IOException {
writePrim("double",name,val,false);
}
@Override
public void writeDouble(String name, double val) throws IOException {
writeDouble(name,Double.toString(val));
}
public void writeDate(String name, Date val) throws IOException {
// using a stringBuilder for numbers can be nice since
// a temporary string isn't used (it's added directly to the
// builder's buffer.
cal.setTime(val);
sb.setLength(0);
int i = cal.get(Calendar.YEAR);
sb.append(i);
sb.append('-');
i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
if (i<10) sb.append('0');
sb.append(i);
sb.append('-');
i=cal.get(Calendar.DAY_OF_MONTH);
if (i<10) sb.append('0');
sb.append(i);
sb.append('T');
i=cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.MINUTE);
if (i<10) sb.append('0');
sb.append(i);
sb.append(':');
i=cal.get(Calendar.SECOND);
if (i<10) sb.append('0');
sb.append(i);
i=cal.get(Calendar.MILLISECOND);
if (i != 0) {
sb.append('.');
if (i<100) sb.append('0');
if (i<10) sb.append('0');
sb.append(i);
// handle canonical format specifying fractional
// seconds shall not end in '0'. Given the slowness of
// integer div/mod, simply checking the last character
// is probably the fastest way to check.
int lastIdx = sb.length()-1;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
if (sb.charAt(lastIdx)=='0') {
lastIdx--;
}
sb.setLength(lastIdx+1);
}
}
sb.append('Z');
writeDate(name, sb.toString());
}
@Override
public void writeDate(String name, String val) throws IOException {
writePrim("date",name,val,false);
}
@ -808,24 +618,8 @@ final public class XMLWriter {
// OPT - specific writeInt, writeFloat, methods might be faster since
// there would be less write calls (write("<int name=\"" + name + ... + </int>)
//
public void writePrim(String tag, String name, String val, boolean escape) throws IOException {
// OPT - we could use a temp char[] (or a StringBuilder) and if the
// size was small enough to fit (if escape==false we can calc exact size)
// then we could put things directly in the temp buf.
// need to see what percent of CPU this takes up first though...
// Could test a reusable StringBuilder...
// is this needed here???
// Only if a fieldtype calls writeStr or something
// with a null val instead of calling writeNull
/***
if (val==null) {
if (name==null) writer.write("<null/>");
else writer.write("<null name=\"" + name + "/>");
}
***/
int contentLen=val.length();
private void writePrim(String tag, String name, String val, boolean escape) throws IOException {
int contentLen = val==null ? 0 : val.length();
startTag(tag, name, contentLen==0);
if (contentLen==0) return;
@ -836,10 +630,10 @@ final public class XMLWriter {
writer.write(val,0,contentLen);
}
writer.write("</");
writer.write('<');
writer.write('/');
writer.write(tag);
writer.write('>');
}
}

View File

@ -22,7 +22,6 @@ import org.apache.solr.search.function.ValueSource;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.util.BCDUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -60,10 +59,6 @@ public class BCDIntField extends FieldType {
return BCDUtils.base10kSortableIntToBase10(indexedForm);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeInt(name,toExternal(f));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeInt(name,toExternal(f));
}

View File

@ -17,7 +17,6 @@
package org.apache.solr.schema;
import org.apache.solr.response.XMLWriter;
import org.apache.lucene.document.Fieldable;
import java.io.IOException;
@ -25,10 +24,6 @@ import java.io.IOException;
* @version $Id$
*/
public class BCDLongField extends BCDIntField {
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeLong(name,toExternal(f));
}
@Override
public Long toObject(Fieldable f) {
return Long.valueOf( toExternal(f) );

View File

@ -17,7 +17,6 @@
package org.apache.solr.schema;
import org.apache.solr.response.XMLWriter;
import org.apache.lucene.document.Fieldable;
import java.io.IOException;
@ -25,10 +24,6 @@ import java.io.IOException;
* @version $Id$
*/
public class BCDStrField extends BCDIntField {
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr(name,toExternal(f));
}
/**
* This only works for strings that represent an interger. If the string
* is not an integer, it will not survive the base10k conversion!

View File

@ -18,7 +18,6 @@
package org.apache.solr.schema;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.common.util.Base64;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.Field;
@ -30,10 +29,6 @@ import java.nio.ByteBuffer;
public class BinaryField extends FieldType {
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr( name, toBase64String(toObject(f)) );
}
private String toBase64String(ByteBuffer buf) {
return Base64.byteArrayToBase64(buf.array(), buf.position(), buf.limit()-buf.position());
}

View File

@ -27,7 +27,6 @@ import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.analysis.SolrAnalyzer;
import java.util.Map;
@ -128,10 +127,6 @@ public class BoolField extends FieldType {
}
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeBool(name, f.stringValue().charAt(0) =='T');
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeBool(name, f.stringValue().charAt(0) =='T');
}

View File

@ -22,7 +22,6 @@ import org.apache.lucene.search.cache.ByteValuesCreator;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.ByteFieldSource;
@ -46,11 +45,6 @@ public class ByteField extends FieldType {
return new ByteFieldSource( new ByteValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeByte(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();
@ -67,7 +61,7 @@ public class ByteField extends FieldType {
try {
byte val = Byte.parseByte(s);
writer.writeByte(name, val);
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.

View File

@ -28,7 +28,6 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.DateUtil;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.*;
import org.apache.solr.util.ByteUtils;
@ -220,10 +219,6 @@ public class DateField extends FieldType {
return new OrdFieldSource(field.name);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeDate(name, toExternal(f));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeDate(name, toExternal(f));
}

View File

@ -21,11 +21,8 @@ import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.DoubleValuesCreator;
import org.apache.lucene.search.cache.FloatValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.DoubleFieldSource;
import org.apache.solr.search.function.FloatFieldSource;
import org.apache.solr.search.function.ValueSource;
import java.io.IOException;
@ -49,10 +46,6 @@ public class DoubleField extends FieldType {
return new DoubleFieldSource( new DoubleValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeDouble(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();

View File

@ -19,11 +19,9 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FloatFieldSource;
import org.apache.solr.search.function.FileFloatSource;
import org.apache.solr.search.QParser;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.common.SolrException;
import java.util.Map;
@ -76,10 +74,6 @@ public class ExternalFileField extends FieldType {
this.schema = schema;
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
throw new UnsupportedOperationException();
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
throw new UnsupportedOperationException();
}

View File

@ -17,42 +17,34 @@
package org.apache.solr.schema;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.noggit.CharArr;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.OrdFieldSource;
import org.apache.solr.search.Sorting;
import org.apache.solr.search.QParser;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.analysis.SolrAnalyzer;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.Sorting;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.util.ByteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.io.Reader;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
/**
* Base class for all field types used by an index schema.
@ -475,11 +467,6 @@ public abstract class FieldType extends FieldProperties {
log.trace("FieldType: " + typeName + ".setQueryAnalyzer(" + analyzer.getClass().getName() + ")" );
}
/**
* Renders the specified field as XML
*/
public abstract void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException;
/**
* calls back to TextResponseWriter to write the field value
*/

View File

@ -20,13 +20,10 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.FloatValuesCreator;
import org.apache.lucene.search.cache.LongValuesCreator;
import org.apache.solr.search.function.LongFieldSource;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FloatFieldSource;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -46,10 +43,6 @@ public class FloatField extends FieldType {
return new FloatFieldSource( new FloatValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeFloat(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();

View File

@ -25,7 +25,6 @@ import org.apache.lucene.spatial.DistanceUtils;
import org.apache.lucene.spatial.tier.InvalidGeoException;
import org.apache.solr.common.SolrException;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SolrConstantScoreQuery;
import org.apache.solr.search.SpatialOptions;
@ -68,12 +67,6 @@ public class GeoHashField extends FieldType implements SpatialQueryable {
new LiteralValueSource(geohash), options.radius), "0", String.valueOf(options.distance), true, true));
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f)
throws IOException {
xmlWriter.writeStr(name, toExternal(f));
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f)
throws IOException {

View File

@ -24,7 +24,6 @@ import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.IntFieldSource;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -44,10 +43,6 @@ public class IntField extends FieldType {
return new IntFieldSource(new IntValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeInt(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();

View File

@ -26,7 +26,6 @@ import org.apache.lucene.spatial.tier.InvalidGeoException;
import org.apache.lucene.util.Bits;
import org.apache.solr.common.SolrException;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SolrIndexReader;
import org.apache.solr.search.SpatialOptions;
@ -267,11 +266,6 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery
return true;
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr(name, f.stringValue());
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeStr(name, f.stringValue(), false);

View File

@ -17,25 +17,10 @@
package org.apache.solr.schema;
import org.apache.solr.common.SolrException;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.OrdFieldSource;
import org.apache.solr.util.DateMathParser;
import java.util.Map;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* This class is <b>NOT</b> recommended for new users and should be

View File

@ -19,12 +19,9 @@ package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.ByteValuesCreator;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.LongValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.IntFieldSource;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.LongFieldSource;
@ -49,11 +46,6 @@ public class LongField extends FieldType {
return new LongFieldSource( new LongValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeLong(name, f.stringValue());
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();

View File

@ -29,7 +29,6 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SpatialOptions;
import org.apache.solr.search.function.VectorValueSource;
@ -117,11 +116,6 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable {
throw new UnsupportedOperationException("PointType uses multiple fields. field=" + field.getName());
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr(name, f.stringValue());
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeStr(name, f.stringValue(), false);

View File

@ -24,7 +24,6 @@ import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.*;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.SolrIndexReader;
@ -100,9 +99,6 @@ public class RandomSortField extends FieldType {
return new RandomValueSource(field.getName());
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException { }
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException { }

View File

@ -21,7 +21,6 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -116,11 +115,6 @@ public final class SchemaField extends FieldProperties {
+ "}";
}
public void write(XMLWriter writer, String name, Fieldable val) throws IOException {
// name is passed in because it may be null if name should not be used.
type.write(writer,name,val);
}
public void write(TextResponseWriter writer, String name, Fieldable val) throws IOException {
// name is passed in because it may be null if name should not be used.
type.write(writer,name,val);

View File

@ -18,12 +18,10 @@ package org.apache.solr.schema;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArray;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.ShortValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.ShortFieldSource;
@ -52,11 +50,6 @@ public class ShortField extends FieldType {
return new ShortFieldSource(new ShortValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeShort(name, f.stringValue());
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String s = f.stringValue();
@ -74,7 +67,7 @@ public class ShortField extends FieldType {
try {
short val = Short.parseShort(s);
writer.writeShort(name, val);
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.

View File

@ -31,7 +31,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.solr.util.ByteUtils;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -73,11 +72,6 @@ public class SortableDoubleField extends FieldType {
out.write( indexedToReadable(ByteUtils.UTF8toUTF16(input)) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
xmlWriter.writeDouble(name, NumberUtils.SortableStr2double(sval));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
writer.writeDouble(name, NumberUtils.SortableStr2double(sval));

View File

@ -31,7 +31,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.solr.util.ByteUtils;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -73,11 +72,6 @@ public class SortableFloatField extends FieldType {
out.write( indexedToReadable(ByteUtils.UTF8toUTF16(input)) );
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
xmlWriter.writeFloat(name, NumberUtils.SortableStr2float(sval));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
writer.writeFloat(name, NumberUtils.SortableStr2float(sval));

View File

@ -31,7 +31,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.solr.util.ByteUtils;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -76,13 +75,6 @@ public class SortableIntField extends FieldType {
return NumberUtils.SortableStr2int(f.stringValue(), 0, 3);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
// since writeInt an int instead of a String since that may be more efficient
// in the future (saves the construction of one String)
xmlWriter.writeInt(name, NumberUtils.SortableStr2int(sval,0,sval.length()));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
writer.writeInt(name, NumberUtils.SortableStr2int(sval,0,sval.length()));

View File

@ -31,7 +31,6 @@ import org.apache.lucene.index.IndexReader;
import org.apache.solr.util.ByteUtils;
import org.apache.solr.util.NumberUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import java.util.Map;
import java.io.IOException;
@ -73,11 +72,6 @@ public class SortableLongField extends FieldType {
return NumberUtils.SortableStr2long(f.stringValue(),0,5);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
xmlWriter.writeLong(name, NumberUtils.SortableStr2long(sval,0,sval.length()));
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
String sval = f.stringValue();
writer.writeLong(name, NumberUtils.SortableStr2long(sval,0,sval.length()));

View File

@ -19,14 +19,9 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.StringIndexDocValues;
import org.apache.solr.search.QParser;
import org.apache.solr.util.ByteUtils;
@ -44,10 +39,6 @@ public class StrField extends FieldType {
return getStringSort(field,reverse);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeStr(name, f.stringValue(), true);
}

View File

@ -33,7 +33,6 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.util.ByteUtils;
@ -67,10 +66,6 @@ public class TextField extends FieldType {
return getStringSort(field, reverse);
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
xmlWriter.writeStr(name, f.stringValue());
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
writer.writeStr(name, f.stringValue(), true);
}

View File

@ -26,7 +26,6 @@ import org.apache.solr.analysis.TrieTokenizerFactory;
import org.apache.solr.search.function.*;
import org.apache.solr.search.QParser;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.SortField;
@ -92,17 +91,6 @@ public class TrieDateField extends DateField {
return new TrieDateFieldSource( new LongValuesCreator( field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER, CachedArrayCreator.CACHE_VALUES_AND_BITS ));
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
byte[] arr = f.getBinaryValue();
if (arr==null) {
xmlWriter.writeStr(name, TrieField.badFieldString(f));
return;
}
xmlWriter.writeDate(name,new Date(TrieField.toLong(arr)));
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
byte[] arr = f.getBinaryValue();

View File

@ -32,7 +32,6 @@ import org.apache.noggit.CharArr;
import org.apache.solr.analysis.*;
import org.apache.solr.common.SolrException;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
import org.apache.solr.search.MutableValueDate;
import org.apache.solr.search.MutableValueLong;
import org.apache.solr.search.QParser;
@ -193,33 +192,6 @@ public class TrieField extends FieldType {
}
}
public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
byte[] arr = f.getBinaryValue();
if (arr==null) {
xmlWriter.writeStr(name, badFieldString(f));
return;
}
switch (type) {
case INTEGER:
xmlWriter.writeInt(name,toInt(arr));
break;
case FLOAT:
xmlWriter.writeFloat(name,toFloat(arr));
break;
case LONG:
xmlWriter.writeLong(name,toLong(arr));
break;
case DOUBLE:
xmlWriter.writeDouble(name,toDouble(arr));
break;
case DATE:
xmlWriter.writeDate(name,new Date(toLong(arr)));
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
}
}
public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
byte[] arr = f.getBinaryValue();

View File

@ -26,7 +26,6 @@ import org.apache.lucene.document.Fieldable;
import org.apache.lucene.search.SortField;
import org.apache.solr.common.SolrException;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.response.XMLWriter;
/**
* This FieldType accepts UUID string values, as well as the special value
@ -53,12 +52,6 @@ public class UUIDField extends FieldType {
return getStringSort(field, reverse);
}
@Override
public void write(XMLWriter xmlWriter, String name, Fieldable f)
throws IOException {
xmlWriter.writeStr(name, f.stringValue());
}
@Override
public void write(TextResponseWriter writer, String name, Fieldable f)
throws IOException {