Hierarchical Navigation
Overview
It’s very common that the navigation for facets such as “Category” should support hierarchical navigation so that subcategories can be listed under categories. This is also sometimes referred to as a “nested” category navigation.
Example
This is done through the Hierarchy API and can be accomplished by following these steps.
This documentation is assuming you have already gone through the QuickStart process with the QuickStart Outdoor Demo Data. If this is not the case, then follow the instructions for setting that up on the Developer Portal.
The API calls needed for this feature are included in this Postman collection. This would be very similar to the Postman collection used in the standard QuickStart set up. <https://hawksearch-sales.demos.hawksearch.com/sales/quickstart-sandbox/HawkSearch_Hierarchy_QuickStart_Collection.postman_collection.json>
Hierarchy Field
This is where you will store the hierarchy values as you will see below. You can do this by logging into the HawkSearch account and navigating to Workbench -> Data Management -> Fields and copying over the field for “category.” In this new field, you want to select “Is Hierarchical Field?” You can call the field “Nested Category” to distinguish it from the original category field, which can remain in place.
Hierarchy Facet
The next step is to create a new facet of type “Nested” and point it to your new field. You can do this by logging into your HawkSearch account and navigating to Workb600ench -> Data Management -> Facets and copying the facet for “category.” In this case you will want to change the setting for type “Nested Category”
Create a new Index
Since you have added these new fields, you will need to create a new index. Once again, use the Postman collection from the QuickStart guide to generate a new index with your new fields and facets.
Hierarchy Data
Now that your new field and facet are in place and you have created a new index, you need to create your hierarchy data in your index. For the demo purposes, the navigation will look like this:
Which means the data will look like this:
| Field | Notes |
|---|---|
| HierarchyId | This can be any value you like – it serves as the identifier for the children nodes in the ParentHierarchyId |
| Name | The name of the value in the facet as it will appear on the website |
| ParentHierarchyId | The pointer to the parent from a child node |
| IsActive | Indicates if the value should be shown on the site |
Note that the first row needs to be the name of the field itself with the ParentHierarchyId set to 0.
You can download this sample data from here: https://hawksearch-sales.demos.hawksearch.com/sales/quickstart-sandbox/nested_category_data.csv
You can run the “Hierarchy Data” request from the postman collection using the CSV above. This process is described in the initial QuickStart set up.
Data for indexing
The data in this CSV file is very similar to the data in the main QuickStart demo. The difference is the new field values for the Nested Category field. Note that children values need to include both the child HierarchyId as well as the parent.
The data looks like this:
You can use this CSV to run the postman collection with “Bulk Product Creation” request in the Postman collection.
https://hawksearch-sales.demos.hawksearch.com/sales/quickstart-sandbox/dataforhierarchyindexing.csv
Rebuild Hierarchy
After your data is indexed, run the final command for rebuilding the hierarchy. It’s a simple endpoint in the postman collection.
Retrieve Hierarchy
If you would like to see the hierarchy in the index, you can use this endpoint. It’s included in the postman collection.
Updated about 16 hours ago
