Solr Faceted Search Example in Spring and Thymeleaf

In an earlier NixMash post on Solr Facet Searching we displayed a list of Product Categories and their respective Product Counts in the console. Today we'll use most of what we covered then, but with an added bonus of displaying the results on a web page with Spring MVC and Thymeleaf.

Solr Facet Searching is effective on the web for drilling down into data through hyperlinks. The examples in NixMash Spring v0.2.7 and online here show this drill-down effect, with Product Categories displayed from a Solr Faceted Search and linked to the Products within that category.

As a review we'll look at how the Product Categories are retrieved from the Repository in the Solr module.

Now onto the areas we didn't cover last time, the Spring MVC and Thymeleaf pieces of the pie.

First to the MVC Controller method where we retrieve the FacetPage<Product> collection through our Solr Service (1). We created a simple ProductCategory data container to hold the Category and number of Products (2).

We can now pass the productCategory Model Attribute to the Web Page for Thymeleaf to do its thing.

Source Code Notes for this Post

All source code discussed in this post can be found in my NixMash Spring GitHub repo and viewed online here.

Posted December 31, 2015 02:51 PM EST

More Like This Post