Logical operators
You can combine filter expressions by using conditionals. This allows you to build powerful filtering logic.
AND
AND
is the conjunction operator.
The following filter returns items which meet two conditions: the brand is "abcd"
and the price is 10 or more.
brand == "abcd" AND price.value >= 10
OR
OR
is the alternative operator.
The following filter returns items which meet at least one of the conditions:
- brand is
"abcd"
- the price is 10 or more
brand == "abcd" OR price.value >= 10
If both conditions are met, the filter also matches the items (and/or logic).
NOT
NOT
is the negation operator.
The following filter returns items whose brand is not "abcd"
:
NOT(brand == "abcd")
IF
If you want to add conditional logic to the filter, you can use the IF
statement.
IF(predicate, thenFilter, elseFilter)
where:
predicate
is a logical expression in which you can use the context, but you cannot use properties of the item that is being tested against the filter.thenFilter
- is returned if the predicate is true.elseFilter
- is returned if the predicate is false.
Examples
Example 1:
A basic IF statement:
IF(context.brand == "abcd", brand == "abcd" , brand != "abcd")
- If the context item’s brand is
"abcd"
, the resulting item filter isbrand == "abcd"
(items from the same brand as the context match the filter). - Otherwise, the filter is
brand != "abcd"
(items from all other brands match the filter).
Example 2:
IF statement with a reference to a segmentation and the ALL/NONE
function:
IF(client.segmentations HAS "39d39ad1-6d7b-4401-b067-998bf7d56d9f", price.value > 100, ALL)
If the context profile belongs to the 39d39ad1-6d7b-4401-b067-998bf7d56d9f
segmentation, the resulting item filter is price.value > 100
. Otherwise, the filter matches all items in the database.
Example 3:
IF statement nested in another IF statement:
IF("NewCustomer" IN client.tags, price.value > 100, IF(context.brand == "abcd", price.value <= 100, ALL))
- If the context profile’s tags include
"NewCustomer"
, the item filter isprice.value > 100
. Otherwise, the nested IF statement is evaluated. - In the nested IF statement, if the context item’s brand is
abcd
, the filter isprice.value <= 100
. Otherwise, the filter matches all items in the database.
Example 4:
IF statement with the AND
logical operator in the predicate:
IF("NewCustomer" IN client.tags AND context.brand == "abcd", price.value > 100, price.value <= 100)
If the context profile has the tag NewCustomer
and the context item’s brand is abcd
, the filter matches items whose price is more than 100.
Grouping expressions
The parentheses ()
allow you to group conditions in order to create more complex and nested expressions.
Example:
(brand == "abcd" AND price.value >= 10) OR brand == "efgh"
The filter returns items which meet at least one of the following conditions:
- brand is
"abcd"
while the price is 10 or more (both conditions must be met). - brand is
"efgh"
.