Advanced filters for widget algorithms

  • Updated
This feature is in beta.

Advanced filters let you define your own rules for an algorithm to further personalize the products the algorithm recommends for the widget. You can use visual mode or code mode, which both use Structured Query Language (SQL). Visual mode provides a user-friendly experience of building SQL queries through selectable drop-down lists and value entry fields with some restrictions on how you can build queries, whereas code mode is a text entry box where you must write the SQL code yourself but there are no restrictions on how you build the queries.

Quick and advanced filters are part of editing widget algorithms.

Advanced filter components

Filters include attributes, operators, attribute values, and connection operators. These combine as follows to create a rule:

attribute + operator + attribute value + connection operator + attribute + operator + attribute value

For example:

  • Visual Mode – recommendation category is equal to Buffet OR recommendation category is equal to Breakfast Service (in other words, recommend products where category is "Buffet" or where category is "Breakfast Service")
  • Code Moder.category="Buffet" or r.category="Breakfast Service"

Attributes

The following attributes are available, with the most common being p. and r..

  • p. – (Product) Refers to the product the user is currently viewing. By using p. in the expression, you are telling the recommendation engine to reference that viewed product.
  • r. – (Recommendation) Refers to the recommended product. You must include a recommendation attribute in your filter for it to return any recommendations.
  • lv. – (Last View) Refers to the last viewed product.
  • v. – (Variant) Refers to the variant of the viewed product.
  • rv. – (Recommendation Variant) Refers to variants of the recommended product.
  • u. – (User) Refers to the user attributes.
  • ti. – (Custom Attribute) Refers to some special attributes in a specific site.

In visual mode, only the recommendation attribute (r.) is supported in the first drop-down list of each rule you create. After you select the recommendation attribute from the first drop-down list, and then select an operator, the value drop-down list displays, which lets you select the current or last viewed product, an item from your product catalog, or enter a value. This is because you must start your filter with a recommendation attribute for it to return any recommendations.

In code mode, attributes must start with a prefix followed by a dot, then an attribute name like brand, category, price, and so on. For example, p.brand refers to the currently viewed product's brand.

Operators

The following operators are available.

  • = – is equal to
  • <> – is not equal to
  • =~ – is empty or equal to
  • <>~ – is empty or not equal to
  • < – is less than
  • <= – is less than or equal to
  • > – is greater than
  • >= – is greater than or equal to
  • =* – starts with
  • ~ – contains
  • !~ – does not contain

In visual mode, the operator drop-down list displays the written version of each operator (like is equal to). In code mode, you must use the symbol for each.

Attribute values

The attribute values depend on your product catalog. For example, if you want to only recommend products in a specific category (r.category), then the attribute value must be one of your defined product categories (like r.category="Cookware").

Visual mode automatically populates your available options in the product catalog drop-down list. Code mode requires you to manually enter a valid attribute value.

Connection operators

Use connection operators to concatenate filter rules or rule groups.

  • AND – Both conditions must be met.
  • OR – Only one of the conditions must be met.

For example, r.category = "Jewelry" is a single rule. r.brand = "Cartier" is also a single rule. If you want to connect the rules so that both conditions must be met, use the AND connection operator as follows:

r.category = "Jewelry" AND r.brand = "Cartier"

If you have another pair of rules, where one (but not both) of the pair's conditions must be met, you can separate the rule pairs into groups, then use the OR connection operator as follows:

(r.category = "Jewelry" AND r.brand = "Cartier") OR (r.category = "Jewelry" AND r.brand = "Bulgari")

In this expression, at least one of the following conditions must be met:

  • r.category = "Jewelry" AND r.brand = "Cartier"
  • r.category = "Jewelry" AND r.brand = "Bulgari"

Visual mode uses an All or Any drop-down list to determine the connection operators. In code mode, you must manually enter your connection operators to expand your filter rules.

Build an advanced filter

You can use visual mode or code mode to build advanced filters, but you must start your filter with the recommendation attribute (r.) as that is what provides logic to recommend products. The following are some examples of common advanced filters you can build in visual or code mode.

Show recommendations with specific attribute values

  • r.unitprice["USD"]>20 – Recommend products where the unit price is greater than $20.
  • r.type<>"cleaning supplies" – Recommend products where the type is not cleaning supplies.
  • r.brand="baker & salt" or r.type="baking tools and pastry utensils" – Recommend products where the brand is baker & salt or the type is baking tools and pastry utensils.

Show recommendations that match the user's currently viewed product context

  • r.discount=p.discount – Recommend products with the same discount as the product the user is currently viewing.
  • r.parent_category=p.parent_category – Recommend products from the same parent category as the product the user is currently viewing.
  • r.brand=p.brand – Recommend products with the same brand as the product the user is currently viewing.
  • r.type=p.type – Recommend products with the same type as the product the user is currently viewing.

Show recommendations that match the user's last viewed product context

  • r.sporttype=lv.sporttype – Recommend products with the same sport type as the product the user previously viewed.

Visual mode

In visual mode, only the recommendation attribute (r.) is supported in the first drop-down list of each rule you create. After you select the recommendation attribute from the first drop-down list, and then select an operator, the value drop-down list displays, which lets you select the current or last viewed product, an item from your product catalog, or enter a value. This is because you must start your filter with a recommendation attribute for it to return any recommendations.

To build an advanced filter that uses other attributes (like product, user, and so on) you must use code mode.

When editing an algorithm, Visual Mode displays by default in the Advanced Filters section with an optional toggle to switch to Code Mode. Use the Add group and Add rule options to build the logic for your filter.

  • Add group – Adds a group of rules. You can add more groups and rules within a larger group. This is beneficial when you want the filter to process the logic for the rules within the group together as a unit. You can select if you want to use "and" or "or" logic within the group.
  • Add rule – Adds a single rule. If you select this within a group, the rule is added to the group. If you select it outside a group, the rule is standalone.

Within a group, when you add more than one group or rule, the All or Any drop-down list becomes available.

  • Select All to apply "and" logic, meaning all of the conditions must be met.
  • Select Any to apply "or" logic, meaning at least one of the conditions must be met.

Similarly, when you add more than one group or rule over all, the higher-level All or Any drop-down list becomes available. For example, in the following image, there are two groups. The first group uses "and" logic, the second group uses "or" logic, and then the two groups are connected with "or" logic.

Visual mode example

These instructions walk through building the following advanced filter in visual mode.

Only recommend products where the category is not Catering Appliances and the sale price is less than or equal to 100 pounds.

  1. Click to edit an algorithm in a widget. Visual Mode displays by default in the Advanced Filters section.
  2. Click Add rule.
    • Expand Select field and select category.
    • Expand the operator drop-down list and select is not equal to.
    • Expand Select value and select Catering Appliances.
  3. Click Add rule again.
    • Expand Select field and select saleprice.
    • Expand the operator drop-down list and select is less than or equal to.
    • Enter 100 in the Select value field.
    • Leave GBP selected as the currency.
  4. Leave All selected in the highest level drop-down list to use "and" logic between the two rules.
  5. Click Save.

Code mode

Code mode lets you write SQL code in the following format to build advanced filters.

attribute + operator + "value" [+ connection operator + other expressions]...

For example, if you want to recommend products where the product category is fashion, r.category is the attribute, = is the operator, and Fashion is the value. The code for this is as follows:

r.category = "Fashion"
The value must be inside double quotes.

Following that format, you can expand that SQL code as much as needed. Keep in mind that you must include the recommendation attribute (r.) in your code as that is what provides logic to recommend products.

Code mode example

(r.category = "Jewelry" AND r.brand = "Cartier") OR (r.category = "Jewelry" AND r.brand = "Bulgari")

This code translates as follows:

Recommend products where the category is Jewelry and the brand is Cartier, or recommend products where the category is Jewelry and the brand is Bulgari.