Sitecore Content Hub - Show products as a facet filter in search
I'm working on a Sitecore Content Hub implementation and we wanted to have Products selectable as filter in the Search component for a custom entity that we created.
By default however, M.PCM.Product cannot be selected in the Search component. Product is not in the list of Taxonomy items:
First hurdle: enable that functionality
- Go to Manage > Schema > M.PCM.Product
- Select Settings (in the three dots menu)
- Enable: Taxonomy-enabled definition
Which will then indicate that entities of that definition are taxonomy items.
Enable Taxonomy-enabled definition
Indicates that entities of this definition are taxonomy items, which can be used in a search facet. The definition used for the facet must be a parent of the searchable definition. For example, M.AssetType must be a parent of M.Assets for the asset type facet to appear on the asset details page.
Documentation: https://doc.sitecore.com/ch/en/users/42/content-hub/manage--edit-an-entity-definition.html
After this, you'll be able to select Product in the Facet definition of the Search Component:
Additional configuration
On the relationship, I've made sure that it is configured as a Taxonomy relation.
I'm not 100% sure if this is actually necessary. From my initial testing it didn't seem needed. But it has some additional advantages. And according to the documentation, it defines whether the relation is taken into account when faceting.
Furthermore it needs to be enabled when you want to inherit data and security across your domain model.
If the taxonomy relation is disabled, it won't inherit Product data and any parent entities of a Product neither, so for instance ProductFamily or Category can also be displayed as facets on the a search page, and used as well for your security model.
Checking out the result
On the page I added this Search component, I did not see any products in my search facets.
I created a new product, and that did show up!
The reason for this is that all my Products were already created and each entity has a flag 'Root taxonomy' that gets enabled when you have 'Taxonomy-enabled definition' checked.
But at creation of those products, that flag was disabled. You need to update the value for each entity!
Updating existing products
- Go to Manage > Entities > M.PCM.Product
- Select a product you want to update
- Go to the Technical tab > Edit
- Check: Root taxonomy
Note that this was an ok solution for me since I did not have that many products in Content Hub yet. I'm sure there are other solutions when you need to update lots of products.
Checking out the result - part 2
And finally, on our new page with the search component, we have a facet on the products!
It works :-)