Griff Griff - 4 months ago 47
Java Question

How to specify multiple Spring Data Solr Facet Fields?

According to the spring data solr docs, you can specify facet fields by either using annotations or using the Java API that solr data provides. In the annotation, you can specify multiple facet fields as such:

@Facet(fields = { "clientCode", "state", "productCode"}, limit = 10, minCount= 1)

From the documentation:

Example 2.6.

// produces:
FacetOptions options = new FacetOptions();
options.addFacetOnField(new FieldWithFacetParameters("name").setPrefix("spring"));

How do I add multiple facets using FacetOptions?

It looks like you can only add a single Facet to the query.


You can call addFacetOnField method multiple times to add facets on multiple fields.

options.addFacetOnField(new FieldWithFacetParameters("name").setPrefix("spring"));