Apache Solr open-source search software
added json.wrf, wrapper function: SOLR-56
Yonik Seeleyd2fbaf889f3c
diff --git a/CHANGES.txt b/CHANGES.txtindex 175de25b2b1..fb64c2e962f 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -59,6 +59,9 @@ New FeaturesIn the process, an init(NamedList) method was added to QueryResponseWriterwhich works the same way as SolrRequestHandler.(Bertrand Delacretaz / SOLR-49 / hossman)+28. json.wrf parameter adds a wrapper-function around the JSON response,+ useful in AJAX with dynamic script tags for specifying a JavaScript+ callback function. (Bertrand Delacretaz via yonik, SOLR-56)Changes in runtime behavior1. classes reorganized into different packages, package names changed to Apachediff --git a/src/java/org/apache/solr/request/JSONResponseWriter.java b/src/java/org/apache/solr/request/JSONResponseWriter.javaindex 7ef473225f9..e1bbeec6791 100644--- a/src/java/org/apache/solr/request/JSONResponseWriter.java+++ b/src/java/org/apache/solr/request/JSONResponseWriter.java@@ -41,17 +41,20 @@ class JSONWriter extends TextResponseWriter {private Calendar cal;private String namedListStyle;+ private String wrapperFunction;private static final String JSON_NL_STYLE="json.nl";private static final String JSON_NL_MAP="map";private static final String JSON_NL_ARROFARR="arrarr";private static final String JSON_NL_ARROFMAP="arrmap";+ private static final String JSON_WRAPPER_FUNCTION="json.wrf";public JSONWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {super(writer, req, rsp);namedListStyle = req.getParam(JSON_NL_STYLE);namedListStyle = namedListStyle==null ? JSON_NL_MAP : namedListStyle.intern();+ wrapperFunction = req.getParam(JSON_WRAPPER_FUNCTION);}public void writeResponse() throws IOException {@@ -65,7 +68,13 @@ class JSONWriter extends TextResponseWriter {if (nl.size()>1 && nl.getVal(1) instanceof DocList && nl.getName(1)==null) {nl.setName(1,"response");}+ if(wrapperFunction!=null) {+ writer.write(wrapperFunction + "(");+ }writeNamedList(null, nl);+ if(wrapperFunction!=null) {+ writer.write(")");+ }}protected void writeKey(String fname, boolean needsEscaping) throws IOException {