Set Up Personalized Boosting
Personalization can be a powerful benefit to your users. You can set up boost lists per user or user group. Applying a boost costs the same however many documents it covers; building a very large per-user list has its own cost, since each item in it is a filter.
Scenario: An online grocery store with two active users.
- User1 regularly buys broccoli and tomatoes
- User2 often buys cheese, especially discounted items
We boost on a single item if a user has bought it once. If they've purchased more than 10 times, we increase the boost strength. We also boost all discounted products globally.
// Set up global boost for all discounted items
Filter discountFilter = engine.CreateValueFilter("discounted", true, out _)!;
Boost globalDiscountBoost = engine.CreateBoost(discountFilter, BoostStrength.Low, out _)!;
// PERSONALISATION PER USER
var userBoosts = new List<Boost>();
// Lists of purchased items by item number
List<long> highPurchases = new List<long>{2, 3}; // Broccoli and cherry tomatoes
List<long> lowPurchases = new List<long>{1}; // Strawberry jam
// One IN filter for each boost level. item_number holds numbers, so the values compare as
// numbers and read the field's index; one filter for the whole list, where OR-ing a filter per
// item was a filter per item and one per combination.
Filter highPurchaseFilter = engine.CreateInFilter("item_number", highPurchases.Cast<object>(), out _)!;
Filter lowPurchaseFilter = engine.CreateInFilter("item_number", lowPurchases.Cast<object>(), out _)!;
userBoosts.Add(engine.CreateBoost(highPurchaseFilter!, BoostStrength.Med, out _)!);
userBoosts.Add(engine.CreateBoost(lowPurchaseFilter!, BoostStrength.Low, out _)!);
userBoosts.Add(globalDiscountBoost);
// Use in query
query.Ranking.Boosts = userBoosts.ToArray(); // a list that is not empty is on