Implement a hierarchical facet strategy

Hierarchical facets let you combine filters in a search, and resolve the problem of an increased number of facet values. To improve system performance and efficiency, implement a hierarchical facet strategy to help your customers navigate your content collection.

To implement hierarchical facets:

  1. In your list of facets, identify any facets that, when combined, yield items that can be classified under others. For example, brand and model.

  2. Create a new facet named by concatenating the names of the facets identified in step 1. For example, brand_model, a concatenated string of brand and model with a _ as delimiter.

  3. Add the new facet as an attribute to the entity and then configure this attribute for use as a facet.

  4. Update the source's extractor logic to set a concatenated string of the facet values. For example, of brand and model, separated by a _.

    For example, Ford_Focus and Ford_Kuga.

  5. Publish the updated source and trigger a reindex.

  6. After the application or page loads, do the following:

    • Request data for your widget for all facets and values. In this example, that is widget rfkid_7,

      Remember to run this request at least once per session.

    • On response, locally store the returned facet objects.

    • Using the data in the lists of facets and facet values, build the required user interface.

  7. Using the following code block as a reference, update your data request for widget rfkid_7.

    {
        "context": {
            "locale": {
                "country": "us",
                "language": "en"
            }
        },
        "widget": {
            "items": [
                {
                    "rfk_id": "rfkid_7",
                    "entity": "car",
                    "sources": [
                        "981588"
                    ],
                    "search": {
                     "limit":100,
                        "content": {
                            "fields": [
                                "brand_model",
                                "year",
                                "city"
                            ]
                        },
                        "facet": {
                            "max": 100,
                            "types": [
     
                                {
                                    "name": "brand_model",
                                    "filtering_options": ["hard_filters", "other_facet_values"]
                                },
                                 {
                                    "name": "year",
                                    "filtering_options": ["hard_filters", "other_facet_values"]
                                },
                                {
                                    "name": "city",
                                    "filtering_options": ["hard_filters", "other_facet_values"]
                                }
                            ]
                        }
                    }
                }
            ]
        }
     }
  8. From that request, using the response for the widget, parse the items of content to determine the count of individual facets. For example, by using the brand_model field, count brand and model in a response with the following facets:

                
    	"facet": [
    	                {
    	                    "name": "brand_model",
    	                    "value": [
    	                        {
    	                            "id": "facetid_eyJ0eXBlIjoiZXEiLCJuYW1lI…",
    	                            "text": "Ford_Focus",
    	                            "count": 6
                            },
                            {
                                "id": "facetid_eyJ0eXBlIjoiHZAiLCoidHlwZ…",
                                    "text": "Ford_Kuga",
                                "count": 2
                            }
    		  ]
    		  

    In this example, the index has 8 Ford cars, comprised of 6 Focus and 2 Kuga.

  9. Populate the list of facets created in step 6. For example:

    []Ford (8)
        []Focus (6)
        []Kuga (2)
If you have suggestions for improving this article, let us know!