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
This commit is contained in:
Jan Høydahl 2012-01-18 14:55:57 +00:00
parent c9361a507d
commit 374f6fc6c1
3 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -235,6 +235,7 @@ class CSVWriter extends TextResponseWriter {
Collection<String> 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);
@ -269,8 +271,8 @@ class CSVWriter extends TextResponseWriter {
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;
}

View File

@ -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);