Hierarchical Categories
Let visitors drill down through your categories: click Electronics, then Computers, then Laptops, narrowing the results at each level. The levels come from your Drupal taxonomy, with nothing to map.
1. Build the tree in Drupal
- In Structure › Taxonomy, create a vocabulary (for example Product Categories) and give each term its Parent term under Relations. Up to 6 levels are used.
- Add a Reference › Taxonomy term field for that vocabulary to your content type or Commerce product type.
- On each item, pick only the most specific term, Laptops. The module adds Computers and Electronics by itself.
2. Send your content again
Run Ingest All Now, or Reindex Everything if you crawl. Each level lands in its own field: level 1 in item_list_element_1_name_sm, level 2 in item_list_element_2_name_sm, and so on. A crawled page carries its first chain of categories in its structured data, which Opensolr reads into the same fields.
| Field | For an item filed under Laptops |
|---|---|
item_list_element_1_name_sm | Electronics |
item_list_element_2_name_sm | Computers |
item_list_element_3_name_sm | Laptops |
An item filed under both Laptops and Tablets (both under Computers) gets both names at level 3; levels 1 and 2 stay Electronics and Computers.
3. Turn on the drill-down facet
- Open Facet Mapping › Facet Configuration.
- On the level you want visitors to start from, usually
item_list_element_1_name_sm, set Widget to Hierarchical (drill-down), give it a Label and tick Enable. - Click Save configuration. The deeper levels are found by themselves.
Good to know
- On a multilingual site the category names are in the language of each translation.
- Several vocabularies on one content type all feed the same level fields.
- A hierarchical facet is not offered in the sort menu.
Check it on /opensolr-search: click a top category in the sidebar and the next level opens.
Facets
- Facets
- Facet Mapping
- Facet Configuration
- Hierarchical Categories