Quick look – Solritas and GUI Generation
Quick look – Solritas and GUI Generation
Join the DZone community and get the full member experience.Join For Free
Get the Edge with a Professional Java IDE. 30-day free trial.
While observing Solr mailing lists we can spot a functionality called Solritas. Sounds strange ? What kind of functionality is it ? How we can use it ? To see the answers to these questions, I invite you to read the rest of the entry.
Please note that the described functionality is available in the version of Solr 1.4 and above. Specifically, in Solr 1.4 and 1.4.1 Solritas is available in Solr, as a contrib module in the contrib directory. However, in version 4.0 (trunk in SVN) it is already a standard functionality.
Solritas, so what is it ?
Reviewing solrconfig.xml file supplied with the sample configuration, in the latest version of Solr, we can find the following definition:
<requestHandler name="/browse"> <lst name="defaults"> <str name="wt">velocity</str> <str name="v.template">browse</str> <str name="v.layout">layout</str> <str name="title">Solritas</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.field">manu_exact</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> <str name="hl">on</str> <str name="hl.fl">text features name</str> <str name="f.name.hl.fragsize">0</str> <str name="f.name.hl.alternateField">name</str> </lst> </requestHandler>
A closer look at this configuration can give a answer to the person who had to deal with different formats of templates. This entry defines a handler based on solr.SearchHandler, but with other than we could suspect response writer – VelocityResponseWriter. It allows processing of the results of responses with the use of template system – Velocity (http://velocity.apache.org/). By using this approach we are able to quickly create a prototype and present search results in an easily accessible way, for example for a business user. There is no need to write applications from scratch – just create your own template and you’re done, you can use Solr, which will wrap search results in your own template.
Configuration described above was copied from the sample configuration provided with Solr. But what do the different parameters do and how we can influence the behavior of Velocity ?
To start using Solritas, we need to do some changes in the configuration:
- Add information that we want to use VelocityResponseWriter.
- Add an appropriate definition of the handler (indicating the use of adequate response writer and configuration of Velocity, for example such as described above).
- If you are using Solr version 1.4.x you should pay special attention to the proper version of the libraries (you must copy them from the /contrib/velocity/src/main/lib directory to the core library directory, in which you want to use Solritas). These libraries are:
Having met these conditions and run the Solr we can see if the functionality is working. For this purpose, use any method to do HTTP request and enter the following address: http://localhost:8983/solr/browse. A simple form should appear that lets you search, have autocomplete functionality and lets You use faceting.
But what about parameters ?
Solritas, or otherwise, VelocityResponseWriter has a number of parameters to configure its behavior. These parameters are:
- v.template – Velocity template name to be used to display the page. Template name should be given without ‘.vm’ extension. In the case of absence of this parameter the template called default will be selected.
- debugQuery - just as with normal queries using the GET method, so, in this case, you can get additional information on processing the request. If you set this parameter to true, apart from additional information in the footer of the page, each result will contain additional diagnostic information.
- v.layout – the name of the template that wrap the template defined in the parameter v.template. In this case, the contents of the template defined in the parameter v.template will be placed in the variable $content to be used within the template defined in the described parameter.
- v.base_dir – specifies the directory from which you want to load templates. The default value is conf/velocity.
- v.properties – specifies the Velocity configuration file. The default value is velocity.properties.
- v.contentsType – sets the HTTP header responsible for transferring information about the type of content.
People who worked with Velocity are aware of the existance of so-called context where objects can be placed to help generate the page templates. VelocityResponseWriter in its context, alows an accessto a series of such helpers. Under the appropriate shortcuts available in the following helpers:
- esc - an instance of EscapeTool
- date – an instance of ComparisonDateTool
- list – an instance of ListTool
- math – an instance of MathTool
- number - an instance of NumberTool
- page – an instance of PageTool
- sort – an instance of SortTool
- request – an object of class SolrQueryRequest
- response – an object of class SolrQueryResponse
For more information on individual classes I invite you to go to http://velocity.apache.org/.
A few words at the end
If you need to quickly generate a graphical user interface and show it, Solritas will be a very good solution. Without writing an additional layer we are able to define a template and show search results in a more friendly form for not technical individuals.
Since this is one of the first entries in the “quick looks” series all ideas and insights will be greatly appreciated. Feel free to comment.
Published at DZone with permission of Rafał Kuć , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.