Back with the tag searching function again. App needs to return content (containing list of tags) that matches a profiles list of tags. The only solution is to do advanced filter intersect > 0. I was wondering if a better solution was created now?
Thanks in advance!
What is the exact use-case?
Iām guessing you have a list field on your data type?
A better solution will likely be to not use a list field. Use a separate object-tag datatype instead.
1 Like
@PhastCo
Can you try comparing two lists using regex expression?
// Define the lists
let list1 = ["tag1", "tag2", "tag3", "tag4"];
let list2 = ["tag1", "tag4"];
// Create a single regex pattern from list2
let pattern = new RegExp(`^(${list2.join("|")})$`);
// Filter list1 to find elements that match the pattern
let matchingTags = list1.filter(tag => pattern.test(tag));
console.log(matchingTags); // Output: ["tag1", "tag4"]
You might need to tweak the regex expression for you use case and make it compatible to bubble.
Not 100% sure if this can work for you. Let me know.
Hi @adamhholmes, thanks for the reply!
Yep, Tag is an object by itself.
Hereās a simplified structure:
Object āProfileā contains a data-field list of āTagsā
Object āContentā contains a data field list of āTagsā
The goal is to return Content which matches with the current userās profile interests (which is basically a list of āTagsā) . Interesct > 0 serves the purposes, although through all these years I was wondering if a better solution has come up
Hey @codefree! Thanks for the reply, certainly an intesting solution which based on your posts should serve the purpose. Iāll have a test later on.
Are you aware if Bubble handles exract with Regex is on the client side or server side? Otherwise it would face the same issue with advanced filter. Thanks for the answer!
It can run on client and server side, depends on where are you implementing it.
Workflow Tab: Client Side
API Workflow: Server Side
Comparing with Advanced filter this might be computational efficient.
Maybe you tried this already:
Do a search for Content
Where tags contains Userās Tags?
Is that not server side?
Does that match any tag and you want to match all tags?
Hey @rico.trevisan, that would be server sided, but contains is used to compare a single item vs. a list. The required use case is comparing two lists which unfortunately doesnāt work with the contains function
Youāve piqued my interest; and/or I donāt understand your use case. Could you share your dbās setup for Content and User?
I use this in a few parts of my app to return a list of Questions where the Question Tag contains a list of Tags (coming from the Multidropdown element).
Yes, the Tag is an object itselfā¦ thatās not what I meant (thatās a given).
You also need an object-tag datatype - in your case a content-tag datatype (donāt use a list field on the content datatype).
Then just do a search for content-tags, whose tag is in the defined list of tags, grouped by content, each itemās content.
That will give you all the ācontentā items who have at least one tag in the defined list of tags, and is all done directly on the database query itself.
Hey Rico:
Hereās a simplified version of the DB:
Data Types:
- Content
- Tag
- User
Contentās Data fields
- List of Tags
Userās data fields
- List of Tags
The requirement:
Returning all Contents with Tags that match Userās Tags
Please let me know if that makes sense!
Thanks for the reply @adamhholmes. I believe I see what youāre saying. Let me know if this would be correct for you scenario:
If I had 20K records of Content & 10K Tags. The Object-Tag (in this case Content-Tag) would need 20M records?
Please let me know if Iām understanding you correctly.
Well, if every piece of content has 1000 tags then yes, that will be 20m records.
But in any case, Iāve been doing a lot of testing on this very subject lately and, unfortunately, it turns out there really isnāt any way to do this with Bubbleās database (the method I mentioned above works great in standard SQL - but it unusably slow in Bubble beyond a few thousand records).
The only way you can do this in a performant, efficient, and scalable way in Bubble is to restrict the number of selectable tags, and then use a number merged searches (one of each Tag).
4 Likes
I agree, that sounds like the most sensible solution. Will be looking to migrate our backend to Xano in the future if our app scales further - speed & WU usage would really be a concern in this case