You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2015/01/10 05:13:59 UTC
[Solr Wiki] Update of "VelocityResponseWriter" by ErikHatcher
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The "VelocityResponseWriter" page has been changed by ErikHatcher:
https://wiki.apache.org/solr/VelocityResponseWriter?action=diff&rev1=36&rev2=37
- = Introduction =
+ Documentation for the VelocityResponseWriter is now here: https://cwiki.apache.org/confluence/display/solr/Response+Writers#ResponseWriters-VelocityResponseWriter
- VelocityResponseWriter (aka [[Solritas]]) enables Solr to respond with content generated from [[http://velocity.apache.org|Velocity]] templates. Along with technologies like SolrJS, this makes Solr itself capable of driving sophisticated search interfaces without the need for an intermediate application server between the browser and Solr.
-
- See [[https://issues.apache.org/jira/browse/SOLR-620|SOLR-620]] for more information.
-
- <<TableOfContents>>
-
-
- = Instructions to use, Solr 1.4+ =
- These steps will get you up and running for the examples below:
-
- * Download and install Solr 1.4.x
- * Fire up Solr: cd example; java -Dsolr.solr.home=../contrib/velocity/src/main/solr/ -jar start.jar
- * Index sample docs: cd example/exampledocs; java -jar post.jar *.xml
- * Hit the examples below...
-
- == Sample Usage ==
- http://localhost:8983/solr/itas
-
- . Renders browse.vm from conf/velocity. Faceted navigation included.
-
- [[http://localhost:8983/solr/itas?v.template.header=Custom%20Header|http://localhost:8983/solr/itas?v.template.header=Custom%20Header]]
-
- . Renders browse.vm, but overrides the header.vm from conf/velocity with the specified value.
-
- http://localhost:8983/solr/itas?debugQuery=true
-
- . Renders browse.vm, adding in explanation views per hit, and a Velocity context dump at the end.
-
- === Using the VelocityResponseWriter in Solr Core ===
- The VelocityResponseWriter is still a contrib component in Solr 1.4.x. In order to use it with the core distributions the following steps need to be followed:
-
- The following jars need to be copied from contrib/velocity/src/main/solr/lib/ to $SOLR_HOME/lib:
-
- * apache-solr-velocity-1.4-dev.jar
-
- * velocity-1.6.1.jar
-
- * velocity-tools-2.0-beta3.jar
-
- * commons-beanutils-1.7.0.jar
-
- * commons-collections-3.2.1.jar
-
- The VelocityResponseWriter uses a more recent version of the commons lang jar than the current version of Solr core, so the jar commons-lang-2.4.jar from .../contrib/velocity/src/main/solr/lib/ should replace $SOLR_HOME/lib/commons-lang-2.1.jar
-
- Add some configuration for this ResponseWriter to solrconfig.xml like this:
-
- {{{
- <queryResponseWriter name="velocity" class="org.apache.solr.request.VelocityResponseWriter"/>
- }}}
- Set up a RequestHandler in solrconfig.xml:
-
- {{{
- <requestHandler name="/itas" class="solr.SearchHandler">
- <lst name="defaults">
- <str name="v.template">browse</str>
- <str name="v.properties">velocity.properties</str>
- <str name="v.contentType">text/html;charset=UTF-8</str>
- <str name="title">Solritas</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">title</str>
- <str name="facet.mincount">1</str>
- <str name="qf">
- text^0.5 title^1.5
- </str>
- </lst>
- <!--<lst name="invariants">-->
- <!--<str name="v.base_dir">/solr/contrib/velocity/src/main/templates</str>-->
- <!--</lst>-->
- </requestHandler>
- }}}
- Copy the .../contrib/velocity/src/main/solr/conf/velocity directory to $SOLR_HOME/conf/. This directory contains the Velocity templates that will be needed by the VelocityResponseWriter, and also a style sheet, main.css. The templates and style sheet can be edited to customize the display.
-
- = Instructions to use, Solr 4.0+ =
- These steps will get you up and running for the examples below:
-
- * Check out Solr trunk: svn co http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/
- * Build Solr: ant clean example
- * Fire up Solr: cd example; java -jar start.jar
- * Index sample docs: cd example/exampledocs; java -jar post.jar *.xml
- * Hit the examples below...
-
- == Sample Usage ==
- http://localhost:8983/solr/browse
-
- . Renders browse.vm from conf/velocity. Faceted navigation included.
-
- [[http://localhost:8983/solr/browse?v.template.header=Custom%20Header|http://localhost:8983/solr/browse?v.template.header=Custom%20Header]]
-
- . Renders browse.vm, but overrides the header.vm from conf/velocity with the specified value.
-
- http://localhost:8983/solr/browse?debugQuery=true
-
- . Renders browse.vm, adding in explanation views per hit, and a Velocity context dump at the end.
-
-
- = Options (All Versions) =
- * {{{v.template}}}: template name to use, without the .vm suffix. If not specified, "default"[.vm] will be used.
- * {{{v.template.<name>}}}: overrides a file system template
- * {{{debugQuery}}}: if true, default view displays explanations for each hit and additional debugging information in the footer.
- * {{{v.json}}}: Escapes and wraps Velocity generated response with v.json parameter as a JavaScript function.
- * {{{v.layout}}}: Template name that wraps main template (v.template). Main template renders to a $content that can be used in layout template.
- * {{{v.base_dir}}}: overwrites default template load path (conf/velocity/).
- * {{{v.properties}}}: specifies a Velocity properties file to be applied, found using the Solr resource loader mechanism. If not specified, no .properties file is loaded. Example: v.properties=velocity.properties where velocity.properties can be found using Solr's resource loader mechanism, for example in the conf/ directory (not conf/velocity which is for templates only). The .properties file could also be located inside a JAR in the lib/ directory, or other locations.
- * {{{v.contentType}}}: sets the value of the HTTP response's Content-Type header (in case (x)html pages should be UTF-8 (instead of ISO-8859-1) encoded, make sure you set this option to {{{text/xml;charset=UTF-8}}} (for XHTML) and {{{text/html;charset=UTF-8}}} (for HTML), respectively)
-
-
- = Velocity Context =
- * {{{esc}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/generic/EscapeTool.html|EscapeTool]] instance
- * {{{date}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/tools/generic/ComparisonDateTool.html|ComparisonDateTool]] instance
- * {{{list}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/tools/generic/ListTool.html|ListTool]] instance
- * {{{math}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/generic/MathTool.html|MathTool]] instance
- * {{{number}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/tools/generic/NumberTool.html|NumberTool]] instance
- * {{{page}}}: a [[http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java?view=markup|PageTool]] instance. page only is added to the context when response is a QueryResponse.
- * {{{request}}}: a [[http://lucene.apache.org/solr/api/org/apache/solr/request/SolrQueryRequest.html|SolrQueryRequest]]
- * {{{response}}}: a [[http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/response/QueryResponse.html|QueryResponse]] most of the time, but in some cases where QueryResponse doesn't like the request handlers output (AnalysisRequestHandler, for example, causes a ClassCastException parsing "response") the response will be a SolrResponseBase object.
- * {{{sort}}}: a Velocity [[http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/tools/generic/SortTool.html|SortTool]] instance
-
- = TODO =
- * Ajax suggest
-
- * Integrate/adapt to SolrJS
-
- * Tie in SIMILE Timeline and SIMILE Exhibit
-
- * Add links in default footer to this wiki page, the Solr request as XML format, and SOLR-620
-
- * Fix multi-valued fields issue, and fl parameter usage.
-
- * Work on "dist" target so this works easily with a nightly build.
-
- * Make Velocity tools and engine configuration pluggable
-
- ----
- CategoryQueryResponseWriter
-