You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2012/01/18 15:56:36 UTC

svn commit: r1232919 - in /lucene/dev/branches/branch_3x/solr: CHANGES.txt core/src/java/org/apache/solr/response/CSVResponseWriter.java core/src/test/org/apache/solr/response/TestCSVResponseWriter.java

Author: janhoy
Date: Wed Jan 18 14:56:36 2012
New Revision: 1232919

URL: http://svn.apache.org/viewvc?rev=1232919&view=rev
Log:
SOLR-2970: CSV ResponseWriter returns fields defined as stored=false in schema

Modified:
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1232919&r1=1232918&r2=1232919&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Wed Jan 18 14:56:36 2012
@@ -110,6 +110,8 @@ Bug Fixes
 * SOLR-2542: Fixed DIH Context variables which were broken for all scopes other 
   then SCOPE_ENTITY (Linbin Chen & Frank Wesemann via hossman)
 
+* SOLR-2970: CSV ResponseWriter returns fields defined as stored=false in schema (janhoy)
+
 Other Changes
 ----------------------
 * SOLR-2922: Upgrade commons-io and commons-lang to 2.1 and 2.6, respectively. (koji)

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java?rev=1232919&r1=1232918&r2=1232919&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java Wed Jan 18 14:56:36 2012
@@ -241,6 +241,7 @@ class CSVWriter extends TextResponseWrit
     Collection<String> fields = returnFields;
 
     Object responseObj = rsp.getValues().get("response");
+    boolean returnOnlyStored = false;
     if (needListOfFields) {
       if (responseObj instanceof SolrDocumentList) {
         // get the list of fields from the SolrDocumentList
@@ -257,6 +258,7 @@ class CSVWriter extends TextResponseWrit
       } else {
         fields.remove("score");
       }
+      returnOnlyStored = true;
     }
 
     CSVSharedBufPrinter csvPrinterMV = new CSVSharedBufPrinter(mvWriter, mvStrategy);
@@ -274,9 +276,9 @@ class CSVWriter extends TextResponseWrit
         FieldType ft = new StrField();
         sf = new SchemaField(field, ft);
       }
-
-      // if we got the list of fields from the index, only list stored fields
-      if (returnFields==null && sf != null && !sf.stored()) {
+      
+      // Return only stored fields, unless an explicit field list is specified
+      if (returnOnlyStored && sf != null && !sf.stored()) {
         continue;
       }
 

Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java?rev=1232919&r1=1232918&r2=1232919&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java Wed Jan 18 14:56:36 2012
@@ -36,7 +36,8 @@ public class TestCSVResponseWriter exten
 
   public static void createIndex() {
     assertU(adoc("id","1", "foo_i","-1", "foo_s","hi", "foo_l","12345678987654321", "foo_b","false", "foo_f","1.414","foo_d","-1.0E300","foo_dt","2000-01-02T03:04:05Z"));
-    assertU(adoc("id","2", "v_ss","hi",  "v_ss","there", "v2_ss","nice", "v2_ss","output"));
+    assertU(adoc("id","2", "v_ss","hi",  "v_ss","there", "v2_ss","nice", "v2_ss","output", "shouldbeunstored","foo"));
+    assertU(adoc("id","3", "shouldbeunstored","foo"));
     assertU(commit());
   }
 
@@ -97,6 +98,10 @@ public class TestCSVResponseWriter exten
     assertEquals("1,,hi\n2,\"hi,there\",\n"
     , h.query(req("q","id:[1 TO 2]", "wt","csv", "csv.header","false", "fl","id,v_ss,foo_s")));
 
+    // test SOLR-2970 not returning non-stored fields by default
+    assertEquals("v_ss,foo_b,v2_ss,foo_f,foo_i,foo_d,foo_s,foo_dt,id,foo_l\n"
+        , h.query(req("q","id:3", "wt","csv", "csv.header","true", "fl","*", "rows","0")));
+
 
     // now test SolrDocumentList
     SolrDocument d = new SolrDocument();
@@ -119,6 +124,7 @@ public class TestCSVResponseWriter exten
     d.addField("v2_ss","nice");
     d.addField("v2_ss","output");
     d.addField("score", "89.83");
+    d.addField("shouldbeunstored","foo");
 
     SolrDocumentList sdl = new SolrDocumentList();
     sdl.add(d1);