Hierarchical Categories
Hierarchical categories enable breadcrumb-style drill-down navigation in your search sidebar: click Electronics to see sub-categories, click Computers to see Laptops. Each level narrows the results. Powered by item_list_element_N_name_sm Solr fields built automatically from your Drupal taxonomy term reference fields.
What You Get
Once configured, your search sidebar shows a collapsible drill-down facet. Visitors click any category value to zoom into that level β a breadcrumb trail and back button keep navigation intuitive:
How It Works
During ingestion, the module scans every entity_reference field on your node or Commerce product that points to a taxonomy_term. For each referenced term, it calls Drupal's loadAllParents() to walk the full ancestor chain, then assigns each level to a positional Solr field:
item_list_element_1_name_smβ root / top-level ancestor (depth 1)item_list_element_2_name_smβ second level (depth 2)item_list_element_3_name_smβ third level (depth 3)- … up to depth 6
You only assign a node to the most specific (leaf) term β the module finds all ancestors automatically. Multiple entity reference fields on the same content type are merged into the same positional fields.
The item_list_element_N_name_sm fields are built automatically during real-time sync and bulk ingestion. You do not configure them in Facet Mapping β they appear in the Facet Configuration table automatically once content is ingested.
Step 1 β Build Your Taxonomy Vocabulary
Go to Structure → Taxonomy in your Drupal admin. Create a new vocabulary (e.g., "Product Categories") or use an existing one.
- Navigate to Structure → Taxonomy → Add vocabulary
- Add your root terms first (e.g., "Electronics", "Clothing", "Books")
- Add child terms β when adding a term, expand Relations and set its Parent term to the appropriate root
- Add leaf terms at the deepest level you need (e.g., "Laptops" under "Computers" under "Electronics")
- You can go up to 6 levels deep β deeper hierarchies are capped at depth 6
Step 2 β Add an Entity Reference Field to Your Content Type
Your content type needs an entity_reference field that references taxonomy terms from your vocabulary.
- Go to Structure → Content types → [Your type] → Manage fields
- Click Add field and choose Reference → Taxonomy term
- Under Reference type, set Vocabularies to your taxonomy (e.g., "Product Categories")
- Save the field settings
- When editing a node, assign it to the most specific (leaf) category β the module walks up to find all ancestors
Do NOT assign a node to both "Electronics" and "Laptops" manually. Assign it to "Laptops" only β the module automatically adds "Electronics" (depth 1) and "Computers" (depth 2) by traversing the parent chain. Assigning to multiple levels of the same tree causes duplicate values at the root depth.
Step 3 β Ingest Your Content
The module picks up entity_reference β taxonomy_term fields automatically during ingestion. No additional configuration is needed on the module side.
- Real-time sync β enabled by default. Every time you save a node, the updated hierarchy is pushed immediately.
- Bulk ingestion β go to the Data Ingestion tab and click Ingest All Now to re-process your full content library if you added the field to existing content types.
Solr Fields Produced
For a product assigned to "Laptops" (child of "Computers" → child of "Electronics"), ingestion produces:
| Solr Field | Value (example) | Depth |
|---|---|---|
item_list_element_1_name_sm |
Electronics | 1 β root / top-level |
item_list_element_2_name_sm |
Computers | 2 β second level |
item_list_element_3_name_sm |
Laptops | 3 β leaf (most specific) |
All fields use the _sm suffix β multi-valued string. If a node belongs to multiple leaf categories (e.g., "Laptops" and "Tablets"), each chain is merged: depth 2 will contain both "Laptops" and "Tablets" while depth 1 contains just "Computers".
Step 4 β Enable the Hierarchical Facet Widget
Once content is ingested, the item_list_element_* fields appear in your Facet Configuration table automatically.
- Go to the Facet Mapping tab in your Opensolr Search settings
- Find
item_list_element_1_name_smin the Facet Configuration section - Set the Widget column to Hierarchical
- Set a Display Label (e.g., "Category", "Product Type")
- Check the Enable checkbox to show the facet on the search page
- Save the configuration
The search page will now show a collapsible drill-down facet. The Opensolr search engine automatically reads all item_list_element_N_name_sm fields for the selected depth. You only configure the depth-1 field β the rest are detected automatically.
Commerce Products
Works identically for Drupal Commerce products. The module detects entity_reference β taxonomy_term fields on your product entity type. Use Structure → Commerce → Product types to add the field, then assign products to leaf category terms.
Multilingual Sites
Each language translation is ingested as a separate Solr document. Taxonomy term labels are resolved in the node's active language β French nodes get French category names, German nodes get German category names.
Multiple Vocabularies
You can have multiple entity reference fields pointing to different vocabularies on the same content type. All are merged into the same item_list_element_N_name_sm fields. Depth 1 may then hold values from several independent trees simultaneously.
Visit your Drupal site's /search/ page and click a top-level category in the sidebar β you should see the facet drill into the next level. See Facets for more on widget types and configuration options.