Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't like the idea of using <a href="http://wiki.apache.org/solr/XsltResponseWriter" rel="nofollow">XsltResponseWriter</a> (which can help int outputting the results in JSON as well), you can create your own <code>SearchComponent</code>, which will modify the output. When you use a custom <code>SearchComponent</code> you can apply different ResponseWriters to the output (xml, json, csv, xslt, etc.).</p> <p>You can learn how to create a custom <code>SearchComponent</code> in <a href="http://sujitpal.blogspot.ru/2011/04/custom-solr-search-components-2-dev.html" rel="nofollow">this article</a>, for example.</p> <p>To use <code>XsltResponseWriter</code>, add this code to <code>solrconfig.xml</code>:</p> <pre><code>&lt;queryResponseWriter name="xslt" class="org.apache.solr.response.XSLTResponseWriter"/&gt; </code></pre> <p>Add a <code>json.xsl</code> file to <code>conf/xslt</code> folder, which has transformation rules for your XML output (when you use <code>wt=xml</code> in your query), something like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:output method="text" indent="no" media-type="application/json"/&gt; &lt;xsl:template match="result"&gt; &lt;xsl:text&gt;{"response":{"docs":[&lt;/xsl:text&gt; &lt;xsl:apply-templates select="doc"/&gt; &lt;xsl:text&gt;]}}&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="doc"&gt; &lt;xsl:if test="position() &amp;gt; 1"&gt; &lt;xsl:text&gt;,&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;xsl:text&gt;{"contributor": [{"userId": &lt;/xsl:text&gt;&lt;xsl:value-of select="userId"/&gt;&lt;xsl:text&gt;, "user": "&lt;/xsl:text&gt;&lt;xsl:value-of select="user"/&gt;&lt;xsl:text&gt;"}]}&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Then you can get this response using a url like:</p> <pre><code>http://localhost:8983/solr/select/?q=id:10&amp;wt=xslt&amp;tr=json.xsl </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload