Search constraint : one "list of Things" is among another "List of Things" (same thing)

I am trying to “Do a Search” on a Products.

one Product can have multiple Tags (field tags).
User can select multiple tags (saved on the User object, field selected_tags)

I want only to show the products which have one or more tag(s) among the user selected_tags. But given that the constraint start with the Product field I cannot use “contains”. Ideally I would write User's selected_tags contains one_of Product's tags.

I have seen in another post (Search parameter list contains all items from a different list) that one could use an Advanced constraint, however I do not see how to get that (manual website is down right now).

If they are both lists then you can use intersect with and it will give you just those that overlap. Would that work for you.

Thank you, but I don’t see how to select intersect in the search constraint field

2020-04-02 13_45_22-Notable

Also I guess this would give me the tags that are both in User selected_tags and in Product tags but what I want is to filter the products themselves.

How to I make an advanced constraint ?

1 Like

I’m on my phone so can’t experiment for you. I think the expression below will only match if the product/item has all the categories a user entered. Can you check please because I can’t remember.

categories contains Do a Search For User (selected_categories)

I also can’t access the manual for many months but it depends on what country you are in. Most bubble users can. Try putting up another post asking someone for a screen grab of that section of the manual.

I can’t remember exactly how you get it but I know you put :filtered after the Search for Items:filtered and then the word Advanced appears and I think it is when you click on the word filtered as opposed to the Search for Items. In effect the Search for Items returns the full list from the server (fast) but the filter is applied in the client’s browser (slow) so if you have a long list it is best not to use this approach.

I know I’ve done something close to what you are talking about before without using advanced filters but I can’t remember exactly how. It was something to do with making the Data Source equals Search for X:merged with Search for Y. It might come to me but I’m offline now for a while.

I tried the formula “tags contains Do a Search For User (selected_tags)” but it stays red (I also tried adding “'s name” at the end). But anyway even if it worked, as I understand it it would show only the Products which contain all the User’s selected_tags. Whereas I want to show Products that have even one or more of the selected tags.

2020-04-02 14_14_49-Shipshop _ Bubble Editor

There are a few things I’m not sure about your data structures so what I have done is build a very simple app with three data tables Product, User and Tags. The Product and User both have a field that is a List of type=Tag (I presume you have this). And, the Tag’s data table has three fields, name, List of type=Product, of List of type=Users (not sure if you have this). The structure involves a little extra work because when a Tag is added/removed from a Product/User you must also update the Tags table. However sometimes when normalising data redundancy is the most efficient way to do what you need to do and this is one of those times.

My simple app works. If you check it out you will see that there are two users. If you run as one user you see all three Products. If you run as the other user you see only two products. Checking the few entries I put in the database you will see the answers are correct - I think they are what you are looking for.

The RG/List on the left is a list of the Current Users’s Tags - it should be a hidden RG of width 1, height 1 and have no element in the cells. Then your main RG, on the right in my sample, uses the hidden RG/Tags’s List of Products. I hope this helps.

1 Like

That is the key ! I had one of those “hhhhhhhmmmm” moment when I read your paragraph. Will try this ASAP but this is the the logic. Thank you very much for the time taken to help :+1:

This is a bit tricky to update a Tag after a Product has been modified, because Tag can have been added but also removed.

The way I solve this which is probably not the most efficient, is first to go through all Tags and remove the Product (ex product_A) which has been modified in each. Then I go over all Tags that are assigned to this product_A and add it to their products list.

=== add ===

2020-04-03 10_10_56-Confikif _ Bubble Editor

=== remove ===

2020-04-03 10_10_34-Confikif _ Bubble Editor

Just wish there was a way to avoid this.

Up to eyes. Will take a look asap

Here’s a link to a full working example which uses your technique (de-normalizing the Products inside the Type Tags) and a auto update Tag's products when a Tag is added/removed to a Product : and the the corresponding bubble :

Note : there is actually no need to use a (hidden) repeating group as the source of the resulting Products repeating group, can get the data directly there

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.