From d90bbdb8361ccc440834126f6cb8ef36eda6a6b1 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Fri, 4 May 2012 05:29:59 +0000 Subject: [PATCH] SOLR-3370: fixed CSVResponseWriter to respect globs in the 'fl' param git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1333760 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +++ .../solr/response/CSVResponseWriter.java | 4 ++++ .../solr/response/TestCSVResponseWriter.java | 19 ++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b5f05f94d29..5faf6be9df0 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -405,6 +405,9 @@ Bug Fixes CoreAdminHandler could return consistent information regardless of wether there is a a default core name or not. (steffkes, hossman) +* SOLR-3370: fixed CSVResponseWriter to respect globs in the 'fl' param + (Keith Fligg via hossman) + Other Changes ---------------------- 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 e801327aa47..26fea81f1a0 100755 --- a/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java @@ -258,6 +258,10 @@ class CSVWriter extends TextResponseWriter { CSVSharedBufPrinter csvPrinterMV = new CSVSharedBufPrinter(mvWriter, mvStrategy); for (String field : fields) { + if (!returnFields.wantsField(field)) { + continue; + } + if (field.equals("score")) { CSVField csvField = new CSVField(); csvField.name = "score"; 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 607d34b1c5c..e4afe095097 100644 --- a/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java @@ -163,6 +163,23 @@ public class TestCSVResponseWriter extends SolrTestCaseJ4 { w.write(buf, req, rsp); String s = buf.toString(); assertTrue(s.indexOf("score") >=0 && s.indexOf("2.718") > 0 && s.indexOf("89.83") > 0 ); + + // Test field globs + rsp.setReturnFields( new ReturnFields("id,foo*", req) ); + buf = new StringWriter(); + w.write(buf, req, rsp); + assertEquals("id,foo_i,foo_s,foo_l,foo_b,foo_f,foo_d,foo_dt\n" + + "1,-1,hi,12345678987654321L,false,1.414,-1.0E300,2000-01-02T03:04:05Z\n" + + "2,,,,,,,\n", + buf.toString()); + + rsp.setReturnFields( new ReturnFields("id,*_d*", req) ); + buf = new StringWriter(); + w.write(buf, req, rsp); + assertEquals("id,foo_d,foo_dt\n" + + "1,-1.0E300,2000-01-02T03:04:05Z\n" + + "2,,\n", + buf.toString()); req.close(); } @@ -176,4 +193,4 @@ public class TestCSVResponseWriter extends SolrTestCaseJ4 { return Arrays.toString(output); } -} \ No newline at end of file +}