I’m struggling to write a search query for a repeating group and am hoping someone can point me in the right direction.
I have a data type called ‘Card’ - it comes in various flavours and I’m trying to ‘match’ one set of them against another set based on the contents of a field called selectedLabels which is a list of another data type ‘Label’.
I’d like two RGs on the page - RG1 shows one set of Cards relevant to that user (this works fine).
I’d like another RG (RG2) to display any ‘matching’ Cards from a different search criteria - by ‘match’ I mean any Cards where the list ‘selectedLabels’ in the group of cards shown in RG1 exactly matches the list ‘selectedLabels’ in the second search.
So if RG1 shows these cards based on some search criteria: Card 1
Selected Labels:
Label A
Label B
Label C
Card 2
Selected Labels:
Label B
Label C
Label D
Card 3
Selected Labels:
Label X
Label Y
Label Z
Then let’s say I have 20 other cards (based on a different search criteria) with two of them having
Selected Labels:
Label A
Label B
Label C
and another two of them having
Selected Labels:
Label X
Label Y
Label Z
Then the expected behaviour would be that the RG2 would display four ‘matches’.
I’ve cycled through a few approaches using ‘contains’, ‘filtered:intersects with’ and most recently ‘filtered:contains list’ , but I don’t seem to be able to get this functionality working…
My current Search for RG2 looks like this:
The ‘Search for Cards’ part of the advanced query is a copy of the search query for RG1.
I saw a similar approach mentioned on another post, but unfortunately I don’t think it fits the brief - like you say, it’d bring back at all cards with at least one of the labels - I’m only looking for exact matches though, where the list of labels exactly matches a list on a card from group 1.
I’m also a bit concerned about the fact this wouldn’t be server side - there will be potentially be a lot of cards in the DB, so sending them all to the client and filtering them all out there (which is my understanding of how the filtering functionality works) feels like it would be increasingly inefficient / non-performant as the number of cards grows.
Any thoughts on a way the intended functionality could be achieved using a server-side approach?
You can hack this a little bit by having a text field as well, containing the UID of each label
Then that allows you to use the “is in” operator and check if the whole string of UIDs of the one in RG2 is in at least one of each of the whole strings of UIDs in RG1.
Editor: cards | Bubble Editor
Run: Bubble | No-code apps
The only downside is it matches exactly, so it would check for the order of those labels as well… maybe that’s fine?
I have a yes/no field on cards to determine will it be in RG1 or RG2 just for test purposes.
“Do a search for : filtered”
in the “do a search for” you can put all your constraints
in the filter put advanced, and then " this [thing]'s [THING] intersect with [element] 's [custom state referring to the THING] count is not 0" OR “this [element]'s [custom state referring to the THING] count is 0”
Thanks so much for taking the time to mock this up - unfortunately I have no control over the order that users will add their labels to their cards initially, so I can’t guarantee that the order would be the same in the ‘matching’ card.
Having said that, there is maybe an opportunity to re-order them somehow. Users add their labels to their Cards one page, and the ‘matching’ feature is shown on another page - I’m wondering if there’s a way for me to re-order lists (at DB level) at the point where they navigate away from the ‘creation’ page. If I can figure that out (currently browsing through plugins to see if any can help) then I think your solution would work…
I’ve also been wondering about the ‘intersects with’ approach you mentioned
Search for Cards:filtered, Advanced: This Card's selectedLabels intersects with RG1's List of Cards:each item's selectedLabels:count > 0
Would this provide exact matches if I was able to get the final count > 0 to instead be count = [the number of items in the original list]? Not sure I can construct a search query that looks like that, but it kinda feels like that might result in the desired behaviour.
I must admit to still being a bit confused as to why ‘contains list’ doesn’t seem to work. From what I’ve been able to pick up from other forum posts, ‘intersects with’ seems to be used when you’re interested in seeing matches where any of the list items overlap, and ‘contains list’ seems to be for when you want the two lists to match on all list items - which is my use case.
Thanks for the suggestion - I’m not quite sure about the ‘custom state’ part of the query (I’m not currently using states against the cards, but would certainly be open to adding one if you think that would help getting this feature to work) - it would be great if you could expand on that a little?
Really appreciate the input though, defo open to all suggestions. This feature is pretty critical to what my app is meant to do!
Setup a database trigger (backend workflows) so when the selectedLabels list changes, set that selectedLabels (text) field like I have it now but sorted by Unique ID
The issue here is lets say RG1 has 4 cards, each of those has 4 selectedLabels, so 16 selectedLabels. If you did count = [the number of items in the original list] RG2’s cards would need to have 16 selectedLabels each
It’s because this checks if RG2’s selectedLabels contains the entire list of each item’s selectedLabels within RG1, so basically same issue as above, it would need all 16 to be a match.
Amazing - thanks for the explainer on the ‘contains list’ and ‘count > 0’ scenarios - that’s starting to make sense.
Next step for me then is to try out triggering the backend workflow you’ve suggested when the users have completed their Card creation step. Haven’t had a need to use BE workflows in my app yet… how hard can it be, right?
Will report back when I’ve managed to set it up - thanks again for the help!
I updated the example, when it creates the Card I removed the portion where it sets the selectedLabels (text) field, and now check backend workflows for the Database Trigger
So under the hood as they change the selectedLabels it will auto-update the text field for you and keep the UIDs sorted the same regardless of their selectedLabel sorting.
It won’t work on my free app but that’s the basic idea of it
I guess it doesn’t have to be a Database Trigger, when they edit or create their card you can just always save it in the text field but sorted… just need to make sure it’s sorted everywhere where they edit their selectedLabels.
either way I guess The database trigger is more hands-off and will handle it in the background, just might take a few 10s of milliseconds to take effect and maybe a little more WU usage?
On my first test case anyway - I think there’s a few different combinations of scenarios I need to review, but it really looks like this is it. Thanks so much - I don’t think it’s a solution I would ever have gotten to on my own. Hugely appreciated!
Also, I think the BE trigger works well with the way my app is set up / the way that users interact with cards during creation / editing