Griff Griff - 14 days ago 8
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: f.name.facet.prefix=spring
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.

Answer

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

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