Search code examples
kentico

Add a smart search filter that looks at parent and grant parent names


I am trying to create a smart filter that looks at the parent and grandparent document names for filtering.

Some context on what I have an what I am trying to do:

I have 3 nested page types:

ProductCategory
  ProductRange
    Product

I also have an All Products page that shows all the products and filters on some fields that are in the Product page type. I an trying to also filter on the category and range names as well.

What is the recommended way to achieve what I am trying to accomplish?


Solution

  • You can use 'smart search filter' web part to accomplish that and filter by NodeAliasPath (see code snippet bellow)

    nodealiaspath;/*;All
    nodealiaspath;/store/*;Store
    nodealiaspath;/store/accessories/*;Accessories
    nodealiaspath;/store/brewers/*;Brewers
    

    This will include only pages that are placed under selected filter, which is basically all under specified node alias path with wildcard(*) at the end. It's also important to use 'Filter clause' as MUST, because that will combine selected nodealiaspath with searched term.

    As an improvement, you can retrieve node alias path dynamically with macro syntax and populate filter with those.