lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r514254 - in /lucene/solr/trunk/src/java/org/apache/solr/request: JSONResponseWriter.java TextResponseWriter.java XMLWriter.java
Date Sat, 03 Mar 2007 22:21:28 GMT
Author: yonik
Date: Sat Mar  3 14:21:27 2007
New Revision: 514254

URL: http://svn.apache.org/viewvc?view=rev&rev=514254
Log:
add Iterable and Iterator support to response writers: SOLR-177

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java
    lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java
    lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java?view=diff&rev=514254&r1=514253&r2=514254
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java Sat Mar  3
14:21:27 2007
@@ -532,24 +532,21 @@
     }
   }
 
-
   public void writeArray(String name, Object[] val) throws IOException {
-    writeArray(name, Arrays.asList(val));
+    writeArray(name, Arrays.asList(val).iterator());
   }
 
-  public void writeArray(String name, Collection val) throws IOException {
+  public void writeArray(String name, Iterator val) throws IOException {
     writer.write('[');
-    int sz = val.size();
     incLevel();
     boolean first=true;
-    for (Object o : val) {
-      if (first) {
-        first=false;
-      } else {
+    while( val.hasNext() ) {
+      if( !first ) indent();
+      writeVal(null, val.next());
+      if( val.hasNext() ) {
         writer.write(',');
       }
-      if (sz>1) indent();
-      writeVal(null, o);
+      first=false;
     }
     decLevel();
     writer.write(']');

Modified: lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java?view=diff&rev=514254&r1=514253&r2=514254
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java Sat Mar  3
14:21:27 2007
@@ -27,6 +27,7 @@
 import java.io.Writer;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -140,10 +141,12 @@
       writeMap(name, (Map)val, false, true);
     } else if (val instanceof NamedList) {
       writeNamedList(name, (NamedList)val);
-    } else if (val instanceof Collection) {
-      writeArray(name,(Collection)val);
+    } else if (val instanceof Iterable) {
+      writeArray(name,((Iterable)val).iterator());
     } else if (val instanceof Object[]) {
       writeArray(name,(Object[])val);
+    } else if (val instanceof Iterator) {
+      writeArray(name,(Iterator)val);
     } else {
       // default... for debugging only
       writeStr(name, val.getClass().getName() + ':' + val.toString(), true);
@@ -164,7 +167,7 @@
 
   public abstract void writeArray(String name, Object[] val) throws IOException;
 
-  public abstract void writeArray(String name, Collection val) throws IOException;
+  public abstract void writeArray(String name, Iterator val) throws IOException;
 
   public abstract void writeNull(String name) throws IOException;
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java?view=diff&rev=514254&r1=514253&r2=514254
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java Sat Mar  3 14:21:27
2007
@@ -25,6 +25,7 @@
 import org.apache.solr.search.DocSet;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.SchemaField;
+import org.apache.solr.schema.TextField;
 
 import java.io.Writer;
 import java.io.IOException;
@@ -290,8 +291,10 @@
       FieldType ft = schema.getFieldType(fname);
       ***/
 
-      SchemaField sf = schema.getField(fname);
-
+      SchemaField sf = schema.getFieldOrNull(fname);
+      if( sf == null ) {
+        sf = new SchemaField( fname, new TextField() );
+      }
       if (fidx1+1 == fidx2) {
         // single field value
         if (version>=2100 && sf.multiValued()) {
@@ -411,10 +414,12 @@
       writeMap(name, (Map)val);
     } else if (val instanceof NamedList) {
       writeNamedList(name, (NamedList)val);
-    } else if (val instanceof Collection) {
-      writeArray(name,(Collection)val);
+    } else if (val instanceof Iterable) {
+      writeArray(name,((Iterable)val).iterator());
     } else if (val instanceof Object[]) {
       writeArray(name,(Object[])val);
+    } else if (val instanceof Iterator) {
+      writeArray(name,(Iterator)val);
     } else {
       // default...
       writeStr(name, val.getClass().getName() + ':' + val.toString());
@@ -468,21 +473,22 @@
   }
 
   public void writeArray(String name, Object[] val) throws IOException {
-    writeArray(name, Arrays.asList(val));
+    writeArray(name, Arrays.asList(val).iterator());
   }
 
-  public void writeArray(String name, Collection val) throws IOException {
-    int sz = val.size();
-    startTag("arr", name, sz<=0);
-    incLevel();
-    for (Object o : val) {
-      // if (sz<indentThreshold) indent();
-      writeVal(null, o);
-    }
-    decLevel();
-    if (sz > 0) {
+  public void writeArray(String name, Iterator iter) throws IOException {
+    if( iter.hasNext() ) {
+      startTag("arr", name, false );
+      incLevel();
+      while( iter.hasNext() ) {
+        writeVal(null, iter.next());
+      }
+      decLevel();
       if (doIndent) indent();
       writer.write("</arr>");
+    }
+    else {
+      startTag("arr", name, true );
     }
   }
 



Mime
View raw message