Show items only if x number of things in common

Hi Bubblers,

I’d like to be able to show a list of Users, but only those who have liked at least 5 of the same pieces of content as the Current User.

Does anyone know how to do this?

Thanks!

This could work, I havent tested
https://puu.sh/DbsZn.png

1 Like

Hi Beau,

Thanks so much for your suggestion!

It does indeed show the relevant users! :slight_smile: It’s a really elegant way and almost gets there. I just need to be able to say ‘Only add Users who have at least 5 pieces of Liked Content in common’.

So essentially ‘Do a Search for Users who have liked at least 5 of the same pieces of Content’. It feels like it should be quite simple actually but I can’t get it.

@romanmg - any ideas? Is there maybe a multiple step way of doing this? Or intersecting lists (which never seems to make intuitive sense to me)

Thanks again!

So keen to get this working - will be the first app I put up on the Bubble Showcase :slight_smile:

im not sure, i can see why it doesnt work now. maybe have liked by list of users on the post and search by that.

1 Like

Thanks for your speedy reply!

Not sure what you mean “have liked by list of users on the post and search by that”?

Hi @mccjon

See if this helps. Unfortunately it uses an Advanced Filter, so if you have a ton of users in the list, it will bog down…but I don’t know how to do it within a search constraint.

In the search for users, we can at least filter out those without Liked Content (if you can narrow further, great!):

And then we intersect each of the users liked content, with the current user and if the count is 5 or greater, we have a match (and we filter out the current user):

Hopefully that gets you closer!

–Ken



Looking to accelerate your app development?

Development of Advanced Apps at https://uniqueideas.com or schedule a free intro session :gift:

Ken Truesdale
LinkedIn

1 Like

@mebeingken, you’re on the right track. But I would say this: Well, shouldn’t “likes” and “likers” (those Users who liked a Post) be properties of the Post and not lists on the User object (that seems overkill and… well, not the right way to do it)?

Indeed, it is. In that case, we would have the following:

The list of all Posts is:

Do a Search for... Posts

Each Post has Likes (a list of type Like… when a User likes a Post we create a Like and attach it to the Post’s Likes, eh?). We know who liked a post because a Like was “Created By” such-and-such a User. Neat! Let’s continue…

The list of all of the Users who liked a Post is then:

Some_Post's Likes's Creator

This resolves to a list of Users who liked that Post. Double neato.

Now, let us say we have a User, User_X. All of the Posts liked by User_X is:

Do a Search for... Posts (constraint: Likes's Creator contains User_X)

This will give us a list of Posts that User_X has liked.

Similarly, let us say we have a User, User_Y. All of the Posts liked by User_Y is:

Do a Search for... Posts (constraint: Likes's Creator contains User_Y)

This is the list of Posts that User_Y has liked.

Now we can ask the question: “Do User_X and User_Y have any liked Posts in common?”

The answer is:

If the first list of posts intersect with the second list of posts

This will resolve to a list of Posts shared by both lists. If this list is “not empty” there must be at least 1 post in common. If this list is “empty” there are no posts in common.

In Bubble terms this list would be:

Do a Search for... Posts (constraint: Likes's Creator contains User_X) intersect with Do a Search for... Posts (constraint: Likes's Creator contains User_Y)

^^^ this resolves to a list of Posts liked by User_X AND User_Y

Are there any items in that list? That’s just:

Do a Search for... Posts (constraint: Likes's Creator contains User_X) intersect with Do a Search for... Posts (constraint: Likes's Creator contains User_Y) is not empty

^^^ this will be yes (true) if there is at least 1 Post in common.

How many items are in common? That’s just the length (:count) of the list:

Do a Search for... Posts (constraint: Likes's Creator contains User_X) intersect with Do a Search for... Posts (constraint: Likes's Creator contains User_Y) :count

^^^ this is the number of Posts that User_X and User_Y have both liked.

Is this number five or more? That’s:

Do a Search for... Posts (constraint: Likes's Creator contains User_X) intersect with Do a Search for... Posts (constraint: Likes's Creator contains User_Y) :count ≥ 5

Done! (Whew! :sweat:)

2 Likes

Hey Keith,

I don’t have enough information about the OPs current structure, existing workflows, workload, etc., to comment on the “right” way to do anything. That’s a far bigger question. I just try to show a way that might work.

Also, I don’t use Creator very often because that door gets closed if creating things through an api external workflow. Just a personal preference, I usually just add a User field.

Oh, and I am not seeing how your solution actually addresses the use case of the OP??? It seems you are comparing two users, however isn’t the task at hand to get a LIST of users that meet the criteria, matched to the current user?

Regardless, maybe that still will turn out to be tip that helps @mccjon!

1 Like

Hi Ken,

Thanks so much for your message!

I’ve implemented it and it works!! :smiley: :smiley: Thanks so much!!!

It can sometimes be quite slow (is this the advanced filter at work?). Do you think a Boost would help this at all?

Thanks again so much for your help!!

It definitely could be causing the slow down. Search constraints happen at the server, but filter happens at the browser. An advanced filter has to go through each item returned so isn’t very useful on large sets of data. You have to limit using search constraints as much as possible.

I think boost only will help server side processing, so might not do much here.

1 Like