Sort by number of shared relationships

Hi All, I hoping someone can help me out.

I’m making a simple recipe app. It has a basic tag functionality. Recipes are tagged, e.g.: an Indian chicken curry might have the tags: Indian, Chicken, & Curry. Users can also select tags they are interested in. Then I’ll have a ‘feed’ list of recipes matching the user’s tags.

I’ve got this functionality working well. I have three collections: Users, Recipes, & Tags. And users and recipes each have a many to many relationship to tags. I then have a list of any recipes where tags match the user (Logged in User> Tags> Recipes)

But, here is the tricky bit. I’m hoping to sort the list based on the number of shared tags. So that recipes that match more of the user’s tags are shown higher in the list.

So for example if the user has the tags ‘chicken’ and ‘curry’ then the recipe for Indian chicken curry, which matches with two tags: Chicken and Curry, will display higher in the list than a recipe like Chicken Snitzel which only matches the ‘chicken’ tag.

I haven’t been able to figure this one out. Can anyone help? Is there a way to set up the sorting that might do this. Or maybe a number of separate lists each corresponding to a shared tag count? Is there a way of determining the number of shared tags?

Thanks all.

Barry

Btw: Loving Adalo, and the friendly community

Oooft! What an interesting case! Although this is certainly possible to do in theory, I think it is quite complicated to set up. I cannot promise that I can get to this any time soon but if no one else from the community is able to pick this up, I will try my best to make a test case for this.

@Victor @parker @pford @vancewong @karimoo Here is a challenge for you all. Any takers? :slight_smile:

Thanks for the reply Colin, much appreciated. If you (when you have time) or any one else in the community come up with a solution, or can even point me in a possible direction, that would be amazing.

Cheers

Barry

Hey @BarryB, this is what I can think of at the moment…

What are the chances that any recipe would have more than 3 or 4 tags? Can perhaps consider having a max of 3 or 4 tags. So each recipe will have maybe 4 separate fields for tags.

The first list on the user’s list of recommended recipes could have a filter for 4 matching tags. The second list could have a filter for 3 matching tags, and so on.

So when the screen loads, it’d load only the lists of recipes that fit the filters, the top one matching up to 4 tags.

I don’t think a list or field that looks at the number of matched tags would work because I believe you’ll allow users to change the tags under their profile at any time. Unless there’s some sort of listener that auto updates whenever these changes are made by the user.

Genius @vancewong . Thank you. That makes total sense to limit the tags and have a slot for each…

Can you briefly talk me through implementation. If I’m using four tag slots (lets call them Tags A, B, C and D), how do I filter the list for say 3 matching tags so that it works whether say Tags A, C & D or Tags B, C,& D match? Or do I need a new list for each possible combo (which I could do but could get unwieldy with all the combos for two tags). Or am I misunderstanding the basic premise?

Thanks again. I really do appreciate your help.

Barry

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.