Solr 1.4 contains a little advertised feature that I think folks ought to know about, Solritas.  What a silly name, you say!  Yeah, ok, call it the boring ol’ VelocityResponseWriter if you like.  Pronunciation accessibility aside, Solritas makes Solr responses look like a real user interface.  Close enough for government work, as they say.  We’ve effectively used Solritas on a number of our recent engagements.  After bringing clients’ data into Solr for the first time, wow, they have a search box, facets, and even toggle-able inline hit score explanations and request/response dumps (when using &debugQuery=true).  And we like to toss the clients’ logo in the upper left for good measure, because we can and it’s easy.

Follow a few straightforward steps to enable Solritas on the example application which ships with Solr 1.4:

  1. Add the VelocityResponseWriter libraries directory to the example solrconfig.xml
  2. Register it as a response writer plugin, named “velocity”.
  3. Copy a templates directory –
    cp -R contrib/velocity/src/main/solr/conf/velocity example/solr/conf/velocity
  4. And while we’re at it, we’ll create a nicely named (URLs matter too) request handler mapping that defaults to the velocity writer type, and a few other basic settings that make sense for the example data.

A diff of the only configuration file touched here, solrconfig.xml, is provided at the end to give you the details of the above steps.

Now Start up Solr

cd example
java -jar start.jar

Index the example data (from another shell)

cd example/exampledocs
java -jar post.jar *.xml

and visit http://localhost:8983/solr/itas. It should looks something like this screenshot:

solritas-initial1-150x150

Hey, I want my XML back!  Ok, append &wt=xml to the URL; it’s the same results, just presented differently.

Adding debugQuery=true to a request, we get a pleasant inline view of Lucene’s explanation for the score computation of each result, see for yourself at http://localhost:8983/solr/itas?q=ipod&debugQuery=true, looks something like this, with explanations initially hidden and toggled into visibility individually by clicking the “toggle explain” link that now appears:

solritas-debug-150x150

There’s a lot of interesting power and potential lurking within Solritas.  Here are a few notable existing capabilities:

  • Templates are searched for in the request parameters, a file system base directory, and the classpath – in that order.  This allows the requesting client to override a sub-template such as the header, on a per-request basis, plugins bundled in JAR files may contain their own templates, and the file system can override embedded templates.
  • Several useful “tools” (as Velocity calls them) are available to format numbers and dates, URL encode strings, and other practically necessary utilities to make data presentable to humans and hyperlinks.
  • Straightforward access within a template to the entire Solr request and response objects

The following diffs are the only changes needed to light up Solritas on Solr 1.4’s example application –

48a49,51
>   <!-- Added path to VelocityResponseWriter library and dependencies -->
>   <lib dir="../../contrib/velocity/src/main/solr/lib"/>
>
501a505,525
>   <!-- /itas mapping for Solritas view with some basic good defaults: like dismax, facet on cat -->
>   <requestHandler name="/itas">
>      <lst name="defaults">
>        <str name="v.template">browse</str>
>        <str name="title">Solritas Demonstration</str>
>
>        <str name="wt">velocity</str>
>        <str name="defType">dismax</str>
>        <str name="q.alt">*:*</str>
>        <str name="rows">10</str>
>        <str name="fl">*,score</str>
>        <str name="facet">on</str>
>        <str name="facet.field">cat</str>
>        <str name="facet.mincount">1</str>
>        <str name="qf">
>           text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
>        </str>
>      </lst>
>   </requestHandler>
>
>
1006a1031,1033
>   <!-- Light up VelocityResponseWriter -->
>   <queryResponseWriter name="velocity" class="org.apache.solr.request.VelocityResponseWriter"/>
>

About Erik Hatcher

Read more from this author

LEARN MORE

Contact us today to learn how Lucidworks can help your team create powerful search and discovery applications for your customers and employees.