Preparing your index
To enable contextual affinities, you can add a new attribute to your index manually or automate the process with a script. This attribute stores context-specific details for each record, allowing for 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 ensures that user preferences, such as a liking for white chairs, are taken into account 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” specifying its color as “Gold” with Hard Goods > Cell Phones > Gold
and also includes a brand-specific categorization under Apple > Gold
.
This approach lets you capture detailed preferences like color and brand affinity within specific contexts.
Adding a contextual affinity to your configuration
Once the contextual affinity has been added to all records in your index, the next step is to declare it as a facet. Then, you can select it as an affinity in the Advanced Personalization dashboard Configuration page. Here, you can streamline your configuration by consolidating attributes. For example, instead of having a separatecolor
or brand
attribute in your setup, you can opt for a hierarchicalAffinities
attribute which contains context-specific information about color and brand.