Filtering and Boosting

In filtering, the expression must return boolean value for each item. If the returned value is true, the item passed the filter; if the value is false, the item does not pass and will be discarded. The value is computed from set property values of the individual items.

Consider the following table of items in sample movie-recommendation domain:

Name
String
Year
Integer
Director
String
Genres
Set
Parental-Advisory
Boolean
Pulp Fiction1994Quentin Tarantino{"Crime Fiction","Drama", "Thriller" }true
King Kong2005Peter Jackson{"Action", "Drama", "Adventure" }false
Fight Club1999David Fincher{"Drama", "Existentialism"}true
The Lord of the Rings: The Return of the King2003Peter Jackson{ "Adventure", "Fantasy", "Action" }false
The Dark Knight2008Christopher Nolan{"Superhero","Drama" ,"Action", "Adventure", "Thriller", "Crime Fiction"}false
Silence of the Lambs1991Jonathan Demme{"Crime Fiction", "Drama", "Thriller", "Horror" }true
Dead Alive1992Peter Jackson{"Horror", "Comedy"}true
… and 10000 other movies

By default, when items are to be recommended to a given user, the recommender selects any items which seem relevant to the user. However, it may be your policy not to recommend items with Parental-Advisory flag set on. Hence you may use the following simple ReQL filtering expression:

ReQL
not 'Parental-Advisory'

Then the recommender may only choose from the following movies:

Name
String
Year
Integer
Director
String
Genres
Set
Parental-Advisory
Boolean
King Kong2005Peter Jackson{"Action", "Drama", "Adventure" }false
The Lord of the Rings: The Return of the King2003Peter Jackson{ "Adventure", "Fantasy", "Action" }false
The Dark Knight2008Christopher Nolan{"Superhero","Drama" ,"Action", "Adventure", "Thriller", "Crime Fiction"}false
… and 5926 other movies

If you want to allow only items without Parental-Advisory which were directed by Peter Jackson (for example because a user selected such a filter at your site) you can do it by:

ReQL
(not 'Parental-Advisory') and ('Director' == "Peter Jackson")
Note

You can access value of a property by putting name of the property into the single quotes. Strings are enclosed in double quotes.

Only the following items can be recommended:

Name
String
Year
Integer
Director
String
Genres
Set
Parental-Advisory
Boolean
King Kong2005Peter Jackson{"Action", "Drama", "Adventure" }false
The Lord of the Rings: The Return of the King2003Peter Jackson{ "Adventure", "Fantasy", "Action" }false

As another example, consider that user entered the Thriller section of your system’s catalog. Then you sure wish to recommend thrillers, ignoring the fact that usually, the user likes comedies.

As the Genres is a set property, you can use the in operator for checking whether Thriller is listed in the item’s genres:

ReQL
"Thriller" in 'Genres'

Only the following items pass the filter:

Name
String
Year
Integer
Director
String
Genres
Set
Parental-Advisory
Boolean
Pulp Fiction1994Quentin Tarantino{"Crime Fiction","Drama", "Thriller" }true
The Dark Knight2008Christopher Nolan{"Superhero","Drama" ,"Action", "Adventure", "Thriller", "Crime Fiction"}false
Silence of the Lambs1991Jonathan Demme{"Crime Fiction", "Drama", "Thriller", "Horror" }true
… and 3141 other movies

Filtering offers you an elegant way of handling deleted/obsolete items in the catalog. In many situations, it may happen that some items become unavailable and hence should not be recommended anymore. Considering interaction data, however, such items may still be important for the recommender. For example, the recommender may find out that users who liked a no more available item, x, will probably like another item, y, which is still available. Therefore, it is undesirable to simply delete x, deleting also all the related interactions in cascade.

With filtering, you may handle item deletes using the following scheme:

  • Create a dedicated item property, such as deleted, of type boolean (the implicit value for all items will be null, which is OK).

  • For deleted items, set the value of deleted true.

  • For recommendations, use the following filter:

    ReQL
    not 'deleted'
  • If the item becomes available again, you may set deleted to false.

Such a mechanism cay easily be extended to control availability over different regions, customer licenses, etc.

In advanced applications, besides filtering, you may wish to boost recommendation rates of some items. In contrast to filtering, where items may be completely blocked, in boosting, you may tell the recommender to prefer some items among others. Indeed, by default, it is a task of the recommender itself to select the items which are the most relevant. However, it may be your policy to purposefully bias the recommender toward your business goals.

For example, considering the above table of movies, one may wish to promote the movies which are new and were filmed after 2000, especially if they were filmed after 2005. Then the following boosting query can handle that:

ReQL
if 'Year' <= 2000 then 1 else (if 'Year' <= 2005 then 1.5 else 2)

As you can see, boosting expressions return numbers rather than booleans as in case of filtering. Specifically, they provide the items with coefficients by which the internal scores determined by the recommender will be multiplied.

The boosting coefficients assigned by the query are shown in the following table:

Name
String
Year
Integer
Boosting
Pulp Fiction19941.0
King Kong20051.5
Fight Club19991.0
The Lord of the Rings: The Return of the King20031.5
The Dark Knight20082.0
Silence of the Lambs19911.0
Dead Alive19921.0
… and 10000 other movies

Use filter:

ReQL
'itemId' not in {"item-127", "item-756", "item-568"}

The three items will not be recommended.

Use filter (usually sent as a dynamic parameter of the API recommendation request):

ReQL
'itemId' in {"item-42", "item-77", "item-1992"}
  • The recommendation engine will re-rank the given set of items for the particular user.
  • It is supported to provide thousands of IDs in the query

Suppose that the items have a string property manufacturer and the user is viewing a product detail page.

If you want to give the user related items using Recommend Items to Item, but restrict them to the manufacturer of the currently viewed item, use filter:

ReQL
'manufacturer' == context_item["manufacturer"]

context_item function is used for retrieving property values of the item, that is currently viewed by the user.

Suppose that the items have a timestamp property published_date. Then you can use this booster:

ReQL
if 'published_date' >= now() - 24 * 60 * 60 then 2 else 1

now returns current UTC timestamp in seconds.

24 * 60 * 60 is the number of seconds in 24 hours.

Suppose that the items have a double property price. Slightly boost items that are more expensive than the currently viewed one with the following booster in Recommend Items to Item:

ReQL
if 'price' > context_item["price"] then 1.2 else 1
  • Suppose that the items have a set property cities. It contains cities in which the items are available.
  • Suppose that the users have a string property city giving the city where each user live.

To recommend only items available in a user’s city, use filter:

ReQL
context_user["city"] in 'cities'

context_user function is used for retrieving property values of the user for which you request the recommendations.

Assume your site contains articles about various topics. The users can choose which topics are interesting for them in order to receive personalized newsletters with articles from these topics.

The subscribed topics are stored for each user in a User property of type set called subscribed_topics.

Each article can belong to multiple topics, stored in the topics item property of the type set.

The following filter allows only items that contain at least one matching topic to be recommended:

ReQL
size(context_user["subscribed_topics"] & 'topics') > 0

The & operator returns the intersection of the two sets, which must be non-empty.

© Copyright 2026, Recombee s.r.o
docs.recombee.com