I wanted to document this here just because it took me a little while to get all the bits working just right so I could have a hierarchical taxonomy display inside a Facet API search facet, rather than a flat display of only the taxonomy terms directly related to the nodes in the current search.
Basically, I had a search facet on a search page that allowed users to filter search results by a taxonomy term, and I wanted it to show the taxonomy's hierarchy:
To do this, you need to do two main things:
- Make sure your taxonomy field is being indexed with taxonomy hierarchy data intact.
- Set up the Facet API facet for this taxonomy term so it will display the full hierarchy.
Let's first start by making sure the taxonomy information is being indexed (refer to the image below):
- In Search API's configuration, edit the Filters for the search index you're using (e.g.
- Make sure the 'Index hierarchy' checkbox is checked.
- In the 'Index hierarchy' Callback settings (which appear after you check the box in step 1), scroll down and make sure you select 'Parent terms' and 'All parent terms' under the Taxonomy type you need to display hierarchically.
- Save the Filters configuration, then reindex all the content on your site (otherwise Solr won't have the updated hierarchy information).
Next, we need to edit the Facet API facet for this taxonomy:
- Go to the taxonomy Facet's configuration page (e.g.
- Check the 'Expand hierarchy' checkbox under 'Display settings' (near the top of the form).
- Set 'Treat parent items as individual facet items' to 'No'.
- Set 'Flatten hierarchy' to 'No'.
- Set 'Minimum facet count' to 0 (to show all terms in the taxonomy).
After you've done that (make sure you reindexed your content!), you should have a nice hierarchical facet display.