Many times, you would want to filter the results of your recommendations to contain only one occurrence of specified item property. For example, if you have a recommendation “popular right now” and the most popular things in your eshop are “Mobile Phones” you will most likely want to enrich the final results so more categories instead of only Mobile Phones are visible to your customers. This is also true if the recommendation is to return shoes of the same model in different sizes, you ideally want to have a parent ID of the item so that you can filter the unique occurrences of it and show the model of the shoe only once.
It can be achieved via JINJA post-filtering, here is an example of the JINJA code that you can use, this example is based on category_level_1, and you would need to edit it if you want to filter any other item property.
{% set reco = recommendations('RecoID', 100) %}
{% set shown_category = [] %}
{% set items = [] %}
{% for item in reco %}
{% if item.category_level_1 not in shown_category %}
{%- append item.category_level_1 to shown_category -%}
{%- append item to items -%}
{% endif%}{%endfor%}
{%for item in items%}
{{item.title}} - {{item.category_level_1}}
{%endfor%}
It will filter the recommendation results to contain only one unique occurrence of the category_level_1. So if the recommendation would return you results 5x Mobile Phones, 6x TVs, in the end this filter would let through only 1 item per each category into the final list.
It iterates over all the items in the reco results, then append the category from that item to separate list and in each other iteration checks if the category was already appended to the final list, if yes, the item is discarded leaving you only with unique categories of each item.