3. SolrOxmClient

The SolrOxmClient provides for easier client communication with Apache Solr. It marshalls/unmarshalls searches and updates to and from a JavaBean. It also allows calls to commit, rollback, and optimize. It is built on top of HttpClientTemplate and HttpClientOxmTemplate.


The Spring configuration and code are from the Solr Client example and are not part of this module.

Spring Configuration

A base URL to Solr and a marshaller and unmarshaller must be defined to use it. To read more about the test look at the Solr Client example.

<bean id="solrOxmClient" class="org.springbyexample.httpclient.solr.SolrOxmClient"
      p:unmarshaller-ref="catalogItemMarshaller" />

Code Example

Example 10. Excerpt from SolrOxmClientIT.testSearch()

Any Solr search parameter can be passed in and the results are unmarshalled into a specific JavaBean.

List<CatalogItem> lCatalogItems = client.search(SEARCH_QUERY_PARAM);

Example 11. Excerpt from SolrOxmClientIT.testPaginatedSearch()

To pass in other parameters to the search, a Map can be passed in. The query is specified by the 'q' key, and the 'start' & 'rows' indicate what range of the results to return.

Map<String, String> hParams = new HashMap<String, String>();
hParams.put("q", "electronics");
hParams.put("start", "5");
hParams.put("rows", "5");

List<CatalogItem> lCatalogItems = client.search(hParams);


Example 12. Excerpt from SolrOxmClientIT.testUpdate()

Updates a list of CatalogItem instances.