WPSolr logo
Search
Close this search box.

Table of contents :

ReQL – How to create business rules for Recombee (with examples)

Image of a reql query

Table of contents :

Recombee is a personalized search & recommendations provider. One of it’s major advantages is that Recombee gives the user the option of modifying the queries from the backend using scenarios and business rules. For example, if you have a Woocommerce website with WPSolr & Recombee, you can hide certain specific items without needing to access the WordPress website, only the Recombee dashboard.

 

You can then construct these business rules using ReQL, a Recombee exclusive Query Language that allows total freedom. You can learn more about it from the official Recombee documentation.

 

How to create business rules

 

Create business rule

Create a business rule in the recombee dashboard

  1. Click on the ‘Business Rules’ tab in the Recombee dashboard.
  2. Click on the ‘+ Create Rule’ button.

 

Set the title of the business rule then create the rule

  1. Set the title in the field. It can be whatever you want but it is recommended to choose a recognizable name so you will easily be able to pick this rule out of a list. For the purpose of this guide, it will be named ‘Rule 1’.
  2. Click on the ‘Create rule’ button to create a rule.

 

Recombee offers an easy way to test out business rules. When clicking on ‘Preview Results’ in the business rule page, a preview appears at the bottom :

 

ReQL preview

 

ReQL filter rules

 

1. Return only one specific items (whitelist)

 

'itemId' == "14911"

 

This business rule will filter out all of the items that do not have 14911 as a value for the ‘itemId’ property. Since the ‘itemId’ is a Recombee unique identifier, only one item will be returned.

 

2. Return multiple specific items

 

'itemId' in ["14911", "14827", "28522"]

 

The recommendations that uses this business rule will only display the three items that have 14911, 14827, 28522 as values for the itemId property.

 

3. Exclude (blacklist) specific items

 

'itemId' != "14911"

or

'itemId' not in ["14911", "14827", "28522"]

 

This will blacklist one or multiple items based on their itemId. Any item but them can be returned to the user.

 

4. Return items with specific values

 

'type' == "post"

 

This will exclusively return items with ‘post’ as the value for the ‘type’ property. It applies to all properties, including date, title, category, and more.

This can return multiple items since the properties do not necessarily have unique values (contrarily to itemId).

 

You could also return items of multiple specific types :

'type' in ["post", "page", "product"]

 

You can once again blacklist posts with specific values using :

'type' != "post"

 

5. Multiple conditions

 

('type' == "post") and size('categories') >= 1

 

This will return the items that are of type post and are in one or more categories (‘categories’ property is of type array).

 

('type' == "post") or size('categories') >= 1

 

This will return the items that are of type post or are in one or more categories (‘categories’ property is of type array).

 

6. Returns items using date

 

At specific date

 

'year' == 2024

 

This will return the items published in 2024. The property will not be named ‘year’ depending on your setup. Change it around if needed.

 

This can also work with month or day :

'week_day' == 1

 

This will return the items that were released on a monday (first day of the week).

 

Between dates

 

'date' >= timestamp("2024-01-01T00:00:00Z")

 

The items returned have been published during or after the first of january 2024.

 

(timestamp("2020-01-01T00:00:00Z") <= 'date') and ('date' < timestamp("2024-01-01T00:00:00Z"))

 

The items returned have been published between 2020 and 2024.

 

Items released this past week

 

'date' >= now() - 60*60*24*7

 

The items returned have been published in the past week (7 days).

 

ReQL boost rules

 

1. Boost a specific item

 

if 'itemId' == "38843" then 1.5 else 1

 

If the id of the item is ‘38843’, it’s score is multiplied by 1.5, for all the other items the score is unchanged. The item associated with this itemId will be placed in the top position (top rank) of recommendations unless it has been excluded by another business rule.

To boost an item’s placement, consider increasing the boost (example : 2) for it to rank higher. Conversely, lowering the boost (example : 0.1) will result in the item appearing at the bottom of the recommendations.

 

2. Boost multiple specific items

 

if 'itemId' in ["14911", "14827", "28522"] then 1.5 else 1

 

The items with these ids will be placed at the top of the recommendations since their score has been boosted by 1.5.

 

3. Boost recent items

 

Boost items published after a certain date

 

if 'date' >= timestamp("2024-01-01T00:00:00Z") then 1.1 else 1

 

Items launched post January 1, 2024, will receive a boost, while the rest will stay unaltered.

 

Boost items released in the past week

 

if 'date' >= now() - 60*60*24*7 then 1.1 else 1

 

Boost the items that were released in the past week (7 days).

Related posts ... not powered by WPSOLR 😊