Use facets

We can also summarize what’s in Solr with faceting, which lets us group Solr documents together and count them. This is like table in R. Faceting can do a query within a query, but more commonly it’s used to summarize unique values in a field. For example, we can find the unique formatIds on data objects:

To facet, we usually do a few things:

  • Add the parameter facet=true
  • Add the parameter facet.field={FIELD} with the field we want to facet (group) on
  • Set rows=0 because we don’t care about the matched Solr documents
  • Optionally specify fq={expression} which filters out Solr documents before faceting. In the above example, we have to do this to count only data objects. Without it, the facet result would include formatIds for metadata and resource maps, which we don’t want.

Currently, the dataone::query() function does not support faceting, so you’ll have to run your queries as a URL.

For additional ways to use faceting (such as pivot faceting), check out the Solr documentation.