A Response Writer generates the formatted response of a search. Solr supports a variety of Response Writers to ensure that query responses can be parsed by the appropriate language or application.
The wt parameter selects the Response Writer to be used. The table below lists the most common settings for the wt parameter.
|wt Parameter Setting||Response Writer Selected|
The XML Response Writer is the most general purpose and reusable Response Writer currently included with Solr. It is the format used in most discussions and documentation about the response of Solr queries.
Note that the XSLT Response Writer can be used to convert the XML produced by this writer to other vocabularies or text-based formats.
The behavior of the XML Response Writer can be driven by the following query parameters.
The version parameter determines the XML protocol used in the response. Clients are strongly encouraged to always specify the protocol version, so as to ensure that the format of the response they receive does not change unexpectedly when the Solr server is upgraded.
|2.0||An <arr> tag was used for multiValued fields only if there was more then one value.||Not supported in Solr 4.|
|2.1||An <arr> tag is used for multiValued fields even if there is only one value.||Not supported in Solr 4.|
|2.2||The format of the responseHeader changed to use the same <lst> structure as the rest of the response.||Supported in Solr 4.|
The default value is the latest supported.
The stylesheet parameter can be used to direct Solr to include a <?xml-stylesheet type="text/xsl" href="..."?> declaration in the XML response it returns.
The default behavior is not to return any stylesheet declaration at all.
|Use of the stylesheet parameter is discouraged, as there is currently no way to specify external stylesheets, and no stylesheets are provided in the Solr distributions. This is a legacy parameter, which may be developed further in a future release.|
If the indent parameter is used, and has a non-blank value, then Solr will make some attempts at indenting its XML response to make it more readable by humans.
The default behavior is not to indent.
The XSLT Response Writer applies an XML stylesheet to output. It can be used for tasks such as formatting results for an RSS feed.
The XSLT Response Writer accepts one parameter: the tr parameter, which identifies the XML transformation to use. The transformation must be found in the Solr conf/xslt directory.
The Content-Type of the response is set according to the <xsl:output> statement in the XSLT transform, for example: <xsl:output media-type="text/html"/>
The example below, from the default solrconfig.xml file, shows how the XSLT Response Writer is configured.
A value of 5 for xsltCacheLifetimeSeconds is good for development, to see XSLT changes quickly. For production you probably want a much higher value.
With Solr 4, the JsonResponseWriter has been changed:
- The default mime type for the writer is now application/json.
- The example solrconfig.xml has been updated to explicitly use this parameter to set the type to text/plain:
Solr has an optional Python response format that extends its JSON output in the following ways to allow the response to be safely evaluated by the python interpreter:
- true and false changed to True and False
- Python unicode strings are used where needed
- ASCII output (with unicode escapes) is used for less error-prone interoperability
- newlines are escaped
- null changed to None
Solr has a PHP response format that outputs an array (as PHP code) which can be evaluated. Setting the wt parameter to php invokes the PHP Response Writer.
Solr also includes a PHP Serialized Response Writer that formats output in a serialized array. Setting the wt parameter to phps invokes the PHP Serialized Response Writer.
Before you use either the PHP or Serialized PHP Response Writer, you may first need to un-comment these two lines in solrconfig.xml:
Solr has an optional Ruby response format that extends its JSON output in the following ways to allow the response to be safely evaluated by Ruby's interpreter:
- Ruby's single quoted strings are used to prevent possible string exploits.
- \ and ' are the only two characters escaped.
- Unicode escapes are not used. Data is written as raw UTF-8.
- nil used for null.
- => is used as the key/value separator in maps.
Here is a simple example of how one may query Solr using the Ruby response format:
The CSV response writer returns a list of documents in comma-separated values (CSV) format. Other information that would normally be included in a response, such as facet information, is excluded.
The CSV response writer supports multi-valued fields, and the output of this CSV format is compatible with Solr's CSV update format. As of Solr 4.3, it can also support pseudo-fields.
These parameters specify the CSV format that will be returned. You can accept the default values or specify your own.
|csv.header||Defaults to true. If false, Solr does not print the column headers|
|csv.null||Defaults to a zero length string. Use this parameter when a document has no value for a particular field.|
These parameters specify how multi-valued fields are encoded. Per-field overrides for these values can be done using f.<fieldname>.csv.separator=|.
|csv.mv.separator||Defaults to the csv.separator value|
Solr also includes a Response Writer that outputs binary format for use with a Java client. See Client APIs for more details.