Filter RG - different data types


So I am building an ecommerce. I have a repeating group with Products. I want to be able to filter the repeating group by Product Type (this is a Option Set field of product types within the Product data type) and by Properties (also an Option Set field within the Product data type but a list of things).

Now I also want to filter it by lenght, width etc. However, those data fields are not in the Product itself. Those data fields are in another data type; Variants. And each variant have a data field for Product (to connect the variant with the product).

I don’t want all variants to be visible in the repeating group. I want the Product to be visible, and once you go to the product page you can see the different variants. I do however want to be able to filter the repeating group with all variants of that product if that makes sense? So if I put the lenght range on a slider between 100 mm - 400 mm I want all products with at least one variant within this range to show up.

I hope you understand my issue and that someone can help me. How would you do this?

You’ll need to use an advanced filter (which is client side so not ideal for performance). This assumes you have product’s variants as a list on the Product type.

Search for Products(with as many constraints as possible):filtered (Advanced: This Product’s Variants:each item’s length:filtered:(This length < slider max and This length > slider min))

Another approach would be to have the Product as a field on the variant. Then do a constrained search for the variant:each item’s Product and filter on the product. Might be more performant depending on your DB setup.

Thank you for your answer.

I have a hard time figuring it out though. Your second approach; how would I go about that? I already have the Product as a field on the Variant. But when I do as you wrote the RG still shows all the variants of each Product (not the variant per se, but the same product shows up three times since I have three variants of that product).

add :unique elements to that