Solritas: Solr 1.4′s Hidden Gem

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 on Solr 1.4 Example

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 with debugQuery=true

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"/>
>

4 Responses to “Solritas: Solr 1.4′s Hidden Gem”

  1. [...] Lucid Imagination » Solritas: Solr 1.4’s Hidden Gem 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. (tags: todo solr userinterface) [...]

    November 5, 2009 14:11Webhamer Weblog: Search & ICT-related blogging » links for 2009-11-05

  2. Hi Erik,

    I was able to get the example working but when trying to deploy under Tomcat 5.5 I appear to be having problems with permissions on creation of “velocity.log”. As far as I can see, all possible locations where the file might be created are writable by the tomcat user and when the test example is run, it doesn’t appear to ever create a “velocity.log” file anywhere.

    Any pointers/ideas on how this might be resolved?

    REGARDS

    INFO: Server startup in 7100 ms
    Nov 23, 2009 12:05:21 AM org.apache.solr.request.UnInvertedField uninvert
    INFO: UnInverted multi-valued field {field=category,memSize=4224,tindexSize=32,time=7,phase1=7,nTerms=0,bigTerms=0,termInstances=0,uses=0}
    Nov 23, 2009 12:05:21 AM org.apache.solr.core.SolrCore execute
    INFO: [] webapp=/solr path=/itas params={} hits=19631 status=0 QTime=76
    Nov 23, 2009 12:05:21 AM org.apache.solr.common.SolrException log
    SEVERE: java.lang.RuntimeException: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.solr.request.VelocityResponseWriter.getEngine(VelocityResponseWriter.java:148)
    at org.apache.solr.request.VelocityResponseWriter.write(VelocityResponseWriter.java:44)
    at org.apache.solr.servlet.SolrDispatchFilter.writeResponse(SolrDispatchFilter.java:325)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:254)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
    at org.apache.solr.request.VelocityResponseWriter.getEngine(VelocityResponseWriter.java:133)
    … 17 more
    Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute :
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    … 22 more
    Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)
    at org.apache.log4j.FileAppender.(FileAppender.java:108)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:69)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    … 24 more

    November 22, 2009 05:32Peter Hancox

  3. To Peter:

    I had the same problem and found a solution at

    http://www.minaret.biz/tips/tomcatLogging.html#velocity

    –Davide Principi

    February 5, 2010 03:28Davide Principi

  4. [...] Solritas – better than xml responses [...]

    June 9, 2010 00:27My Links for Apache Solr 1.4 « Find Time for the Karussell

Leave a Reply