From 374f6fc6c1107234a69e5c0728a5fd665d29a38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Wed, 18 Jan 2012 14:55:57 +0000 Subject: [PATCH] SOLR-2970: CSV ResponseWriter returns fields defined as stored=false in schema git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1232918 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 2 ++ .../java/org/apache/solr/response/CSVResponseWriter.java | 8 +++++--- .../org/apache/solr/response/TestCSVResponseWriter.java | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 1954f7ea3cb..5fbb473c7eb 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -484,6 +484,8 @@ Bug Fixes * SOLR-3042: Fixed Maven Jetty plugin configuration. (David Smiley via Steve Rowe) +* 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) diff --git a/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java b/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java index e35dfde6847..6049dc87b4c 100755 --- a/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java @@ -235,6 +235,7 @@ class CSVWriter extends TextResponseWriter { Collection fields = returnFields.getLuceneFieldNames(); Object responseObj = rsp.getValues().get("response"); + boolean returnOnlyStored = false; if (fields==null) { if (responseObj instanceof SolrDocumentList) { // get the list of fields from the SolrDocumentList @@ -251,6 +252,7 @@ class CSVWriter extends TextResponseWriter { } else { fields.remove("score"); } + returnOnlyStored = true; } CSVSharedBufPrinter csvPrinterMV = new CSVSharedBufPrinter(mvWriter, mvStrategy); @@ -268,9 +270,9 @@ class CSVWriter extends TextResponseWriter { 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; } diff --git a/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java index 4cef0b660f8..6d9a535c740 100644 --- a/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java @@ -36,7 +36,8 @@ public class TestCSVResponseWriter extends SolrTestCaseJ4 { 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 extends SolrTestCaseJ4 { 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("id,foo_b,foo_d,foo_s,foo_f,foo_i,foo_dt,foo_l,v_ss,v2_ss\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 extends SolrTestCaseJ4 { 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);