Facets

Dynamicweb features a generalized search framework usually referred to as Indexing, which can be used to index and query all kinds of data on your solution – productscontentusers, files, etc.

Broadly speaking, Indexing consists of the following elements:

  • Indexes are data structures optimized for data retrieval
  • Queries are used to retrieve data based on criteria you define
  • Facets are used to create filters in frontend
  • Tasks are used to rebuild indexes on a schedule

All of these elements can be heavily configured to suit your particular scenario – and all exist within a so-called repository, which is simply a folder in the file archive containing configuration files.

This article will tell you more about Facets.

Facets are a particular kind of filter which allows customers to refine a product list based on values in the index (Figure 2.1).

Figure 2.1 Frontend example of how facets work

Technically, a facet is a mapping between a query parameter (e.g. Manufacturer) and a list of values from a field in the index (e.g. Manufacturer name) – selecting one of the values then passes the value to the query, and the filtered query result is then returned to frontend.

Facets are created inside facet groups - to create a facet group:

  • Click Add Facets in the repository toolbar to create a facet group
  • Name it
  • Select a Query to pass the facet values to

This opens the facet group configuration view (Figure 2.2).

Figure 2.2 Creating a facet group

From the facet group view you can add three types of facet:

  • A field facet retrieves a list of all possible values found in a particular field in the index
  • A list facet lets you group field values under a common label (“Spring colors”)
  • A term facet is identical to a field facet, but will only retrieve the 2048 most frequently used field options from a field. In general, we don’t recommend faceting on data which requires you to use a term facet, as too many facet options can impact performance.

All three types can calculate the number of matching elements in the query result for each facet option. Facets in a facet group can be sorted via drag & drop.

To show facets in frontend select then on the product catalog app used to publish the index query. By default, all facets are shown in frontend but you can control this with either cascading facets (see below) or directly on each product group.

Field facets retrieve facet options from a particular field in the index – so if the field Colors has twelve different values (blue, green, red, mauve, etc.), twelve different facet options will be available in frontend.

To create a field facet:

  • Click Add field facet on the facet group page
  • Provide a facet name
  • Select a field to retrieve facet options from (fields with more than 2048 different terms cannot be selected - use a term facet instead)
  • Select a query parameter to pass the option values to
  • (optional) Specify a render type

The Show section allows you to specify when the facet should be shown in frontend - Always or Conditionally, based on another facet/parameter having a value, specific or not.

Figure 3.1 Creating field facets

A list facet allows you to manually specify list options and give them custom labels (Figure 4.1).

  • Click Add list facet on the facet group page
  • Provide a facet name
  • Select a field to retrieve facet options from
  • Select a query parameter to pass the option values to
  • (Optional)Specify a render type
  • Create a number of labels and values

The Show section allows you to specify when the facet should be shown in frontend - Always or Conditionally, based on another facet/parameter having a value, specific or not.

Figure 4.1 Creating list facets

If multiple options are given the same label, they will be grouped together – which means that you can use list facets to group facet options under a particular label.

Please note that there is no built-in validation, the values you enter must fit the source data or the facet option will appear empty in frontend.

A term facet behaves almost identical to a field facet, except for the fact that it will only retrieve the 2048 most frequent terms from a field. This makes it possible to facet on fields with a lot of variance in terms without crippling performance completely.

To create a term facet:

  • Click Add field facet on the facet group page
  • Provide a facet name
  • Select a field to retrieve facet options from
  • Select a query parameter to pass the option values to
  • (Optional) Specify a render type

The Show section allows you to specify when the facet should be shown in frontend - Always or Conditionally, based on another facet/parameter having a value, specific or not.

Figure 5.1 Creating term facets

Cascading facets are facets where filters are shown or hidden depending on previously selected facet values. For instance, you have shop where you sell two things; fruit and cars. To help the customer find the right product you have three facets:

  • A Category facet where the customer chooses either Fruit or Cars
  • A Car model type facet where the customer can select Hatchback, Sedan, MPV, SUV & Convertible
  • A Fruit type facet where the customer can select Citrus, Strone fruit, Berries, Melons & Tropical

Obviously, you don’t want to show people interested in cars the fruit type facet – so you use the Show settings to specify that the Category parameter should have the value Fruit before showing the fruit type facet (Figure 6.1).

Figure 6.1 Using the show-settings on a facet to create cascading facets

In this manner, it is possible to create “decision trees” using facets, which is very useful for shops selling many different types of products.

A dynamic facet is a facet which is not predefined inside a repository but is instead generated dynamically based on query string parameters. Dynamic facets are activated on a product catalog app when it is set to index mode (Figure 7.1).

Figure 7.1 Activating dynamic facets

When active, the predefined facet configuration defined in the product catalog facet groups selector can be overwritten by adding query string parameters in the following format:

?DynamicFacets=<FacetName/FieldSystemName>[@Label] – e.g. ?DynamicFacets=NameForSort@Product%20name

When you activate dynamic facets, you have two options:

  • Allow dynamic facets from existing facet groups – this limits the feature to only predefined facets selected on the product catalog
  • Allow dynamic facets for all fields – this allows you to create dynamic facets on all fields, including system fields and facets not selected on the product catalog

As soon as a dynamic facet is specified in the URL, the facet loop will stop outputting the predefined facets and instead output the dynamic facets. If no dynamic facets are specified the loop will output the preselected facets.