Preparing your index
To enable contextual affinities, add a new attribute to your . You can add it by hand, or automate the task with a script. This attribute stores context-specific details in each of your . This gives more relevant search results based on the user’s situation. The following example addshierarchicalAffinities as a contextual affinity attribute:
JSON
Hard Goods > Desk Chairs > White.
This approach considers user preferences, such as a liking for white chairs, only when recommending desk chairs.
In the second record, the hierarchicalAffinities attribute is more flexible.
It categorizes the iPhone 15 under “Hard Goods” and “Cell Phones”.
It also sets the color as “Gold” with Hard Goods > Cell Phones > Gold.
It adds a brand-specific categorization under Apple > Gold.
This approach lets you capture detailed preferences like color and brand affinity in each context.
Adding a contextual affinity to your configuration
After you add the contextual affinity to all records in your index, declare it as a facet. Then, select it as an affinity on the Advanced Personalization Configuration page. Here, you can simplify your configuration by consolidating attributes. For example, instead of separatecolor and brand attributes, use a hierarchicalAffinities attribute that stores color and brand details for each context.