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 formatId
s on data objects:
- https://arcticdata.io/metacat/d1/mn/v2/query/solr/?q=:&fq=formatType:DATA&facet=true&facet.field=formatId&rows=0
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 includeformatId
s 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.