Recommend - Distinct Related Products

Hello, First time here.

I’m trying to implement a “Related Products” Section in a product page, I’ve created the model, trained it, but I’m having an issue where the recommendations are “duplicate” since it’s getting multiple variants of the same products, I’ve tried using queryParams: {distinct: 'true'} without success, and I’m coming here to try to figure how to get it working.
Thanks in advance!

edit: I’ve tried to add Filters where I try to make id | is not | sameASViewItem along with tags (they are both the same), and it doesn’t work

@monteirojmig I think you should be able to do this through the distinct operator. Which attribute have you set as the attributeForDistinct? You’ll want to make sure this attribute is unique across all of the variants, for example:

[
  {
    "name": "2022 Team Shirt (Red)",
    "unique": "2022-team-shirt",
    ...
  },
  {
    "name": "2022 Team Shirt (Green)",
    "unique": "2022-team-shirt",
    ...    
  }
]

In the Index Configuration, under ‘Deduplication and Grouping’, ensure the ‘Attribute for Distinct’ parameter is filled out.

For your request, I would also try to submit the distinct value as either 1 or true (not as a string, however) - it’s possible this isn’t getting converted to a truthy value along the way perhaps. For example:

{
  ...
  queryParameters: {
    distinct: 1
  }
}

More information on the distinct functionality can be found here.

Happy to help further, just let us know! Thanks!

Thank you for the help, I got it working using

queryParameters: {
      distinct: true,
    },

altough sometimes it recommends the product I’m searching recommendations for…

@monteirojmig glad you got it working!

In the recommend call, I would add a filter to exclude the id (or whichever unique identifier you are using) of the active item, which should help with that issue:

{
  ...
  queryParameters: {
    filters: "NOT unique: 2022-team-shirt"
  }
}

Ensure that the unique identifier is set up as a facet (you’ll want to use ‘Facet Display’ in the configuration to hide any facets that should not be visible).

1 Like