How to handle this relationship on Algolia?

Guys, I need help with the following scenario:

Users can collect products by creating his collections. So one user can have many collections, and each collection can have many products. Right now, I only have products index on Algolia.

The question is: how would I get all products of a specified collection? The only solution I could think of would be to store an array of collection_ids as a product attribute, but that would require me to update the product every time a user adds it to a collection, which I’m not sure I want this.

Hi @win I’m not sure I will be very constructive, but I would say that you guessed it right. If you need to search based on a relation, this relation has to be encoded in the data which means that you have to update an index with the relation otherwise Algolia won’t be able to know about it and you won’t be able to search it :slight_smile:

1 Like

Hey @win!

As @Bobylito said you have to have the data there and in sync if you want to be able to use it in your search.

However could you tell us a bit more about what you’re building?

You’re talking about collection IDs, so are you just looking into filtering products by a specific collection?
Are all collections going to be public, or will a user only see his own collections and be able to filter on those?

There might be different valid answers to your issue depending on what you want the search experience to look like :slight_smile: