Changing the Size of Solr Facet Pages

I’m going to write up a post on Solr Faceting, but I wanted to first post a quick how-to on changing the Page Size of a Solr FacetFieldEntry Page. After my experience generating several Solr Facet listings and not finding anything helpful out there on the topic I think it will be helpful.

Setting Page Size on the Facet, Not the Query

We’re accustomed to sending a new PageRequest(0, 20) to a Pageable Solr Query or using a .setPageRequest() to change the page size. Here’s an example.

The problem is that the Solr Query is independent of the Facet Page object. We’ll look at two examples to see what I mean.

In this example we may instinctively want to add a setPageRequest() to the FacetQuery. That, however, would have no effect on our output. Instead it is added to setFacetOptions() of the FacetQuery query.

Let’s look at another example where we rely on JPA Annotations. Here you would think the Pageable object we pass to the findProductCategoryFacets() method would do the job, especially since it is required when returning a Page<> object. But no, we see that we set the PageSize on the @Facet object (limit = 100), not in the method where it is essentially ignored on Facet Queries.

You’re welcome!

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.