Developers
Search…
Filtering
When recommending items to a user, LYNX's AI prediction engine selects the ones that are the most relevant to the user. However it may be your policy to not recommend certain items. To narrow down the scope of the recommendable items you can use the filter parameter when invoking the recommendation API methods.

Filter

A filter is an expression that allows you to filter the recommend items based on the values of their attributes. The attributes on which you can filter are the fields in your catalog. A filter expression defines the condition to be met for the items to be returned and it's a combination of one or more predicates tied together by logical operators (AND, OR, and NOT). A predicate is an expression that returns TRUE or FALSE.

Predicates

A predicate has the following form:
p: [attribute] [comparison operator] [value]
[attribute]
[comparison operator]
[value]
The name of a fileld in your catalog.
See the table below for reference.
Can be a string a number or a boolean value.
String values must be enclosed in single quotes (e.g.'string_value').

Examples

p1: Price > 15
p2: Category = 'Clothing'
p3: InStock = 'Yes'
Since a filter expression is a combination of one or more predicates tied together by logical operators, the following are valid filtering expressions:
Price > 15 (p1)
Price > 15 AND Category = 'Clothing' (p1 AND p2)
Price > 15 AND Category = 'Clothing' AND InStock = 'Yes' (p1 AND p2 AND p3)

Remarks

The order of precedence for the logical operators is NOT (highest), followed by AND, followed by OR. Parentheses can be used to override this precedence in a filter expression.
(Price > 15 OR Category = 'Clothing) AND InStock = 'Yes' ((p1 OR p2) AND p3)

Examples

Consider the following catalog in a sample retail domain:
Id
Title
Category
Price
InStock
SpecialOffer
1234
Black Check Knit Skirt
Clothing
19.00
Yes
Yes
3738
Gold Midi Pencil Skirt
Clothing
34.90
Yes
No
9737
Black Leather Women Bag
Accessories
24.90
No
Yes
1002
White Chain Zip Belt Bag
Accessories
14.90
Yes
No
6343
Leather-Look Leggings
Clothing
13.90
No
No
...
...
...
...
..

Example 1

Suppose USER_A has purchased ITEM_123. You may want to recommend to USER_A other items that are frequently bought together with ITEM_123. However it may be your policy to recommend only items that are in stock. To do so you should use the following simple filtering expression:
InStock='Yes'
The resulting API call should look like this:
1
https://ai.kickdynamic.cloud/api/v1/recommender/YOUR_MERCHANT_ID/items/ITEM_A
2
/bought-together?userId=USER_A&topK=10
3
&attributes=Title,Categoty,Price
4
&filter=InStock='Yes'
Copied!

Example 2

Suppose USER_A has purchased ITEM_123. You may want to recommend to USER_A other items that are frequently bought together with ITEM_123. You may want to recommend only items that are in stock, that belong to the Clothing category and that are on special offer. To do so you should use the following filtering expression:
(InStock='Yes' AND Category='Clothing' AND SpecialOffer='Yes')
The resulting API call shoul look like this:
1
https://ai.kickdynamic.cloud/api/v1/recommender/YOUR_MERCHANT_ID/items/ITEM_A
2
/bought-together?userId=USER_A&topK=10
3
&attributes=Title,Categoty,Price
4
&filter=(InStock='Yes' AND Category='Clothing' AND Promotion='Yes')
Copied!

Example 3

Suppose you want to recommend the most popular items in a specific category, but you also want the recommended items to have a price of at least 15.00 £ (in other words you want the price to be equal or greater than 15.00 £). To achieve your goal you can use the following filtering expression:
(Price >= 15.00)
The resulting API call shoul look like this:
1
https://ai.kickdynamic.cloud/api/v1/recommender/YOUR_MERCHANT_ID/items/top-in-category
2
&attributes=Title,Categoty,Price
3
&filter=(Price >= 15.00)
Copied!

Filtering Operators

Comparison Operators

Operator
Meaning
=
Equal to
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
<>
Not equal to
LIKE
Matches a specified pattern.

The LIKE comparison operator

The LIKE operator determines whether a specific field matches a specified pattern. A pattern can include regular characters and wildcard characters. During pattern matching, regular characters must exactly match the characters specified in the character string. However, wildcard characters can be matched with arbitrary fragments of the character string. Using wildcard characters makes the LIKE operator more flexible than using the = and != string comparison operators.
field [ NOT ] LIKE pattern
fieldis any valid text field in the catalog.
pattern is the specific string of characters to search for in field, and can include the following wildcard characters.
Wildcard character
Description
Example
%
Any string of zero or more characters.
title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title.
_
Any single character.
name LIKE '_ean' finds all four-letter names that end with ean (Dean, Sean, etc...).

Remarks

When you do string comparisons using the LIKE operator, all characters in the pattern string are significant. Significant characters include any leading or trailing spaces.

Logical Operators

Logical operators are used to combine predicates together in order to build more complex filtering expressions.
Operator
Meaning
AND
TRUE if all evaluated expressions are TRUE
OR
TRUE if any of the evaluated expressions is TRUE
NOT
Reverses the value of any other operator

Arithmetic Operators

Operator
Meaning
+
Add
-
Subtract
*
Multiply
/
Divide
%
Modulus
Last modified 6mo ago