Alternative to using filter:advanced

I’m designing an app that would allow a user to find items that fit certain diets. These diets include vegan, gluten free, organic, kosher, soy free, etc.

If a user has multiple dietary needs, for example, they may want gluten free/vegan/soy free items, I only want them to see items that are gluten free AND vegan AND soy free. So if an item is only gluten free and vegan, but not soy free, the item will be filtered out and the user will not see that item.

I came up with a solution, but it uses “Advanced” in the filter feature. The problem is, this results in an extremely slow app in filtering through and getting the results.

What I did:
I created a type ‘diet’ with a field called ‘name’ of type text. So I have diets, named: Vegan, Gluten Free, Soy Free, etc.

I created a type food item with a field called ‘diets’ which is multiple texts (as an item can fit multiple diets). So I can create a food item named sandwich and can assign it a diet: gluten free, vegan, soy free.

I have users with field ‘diets’ where in my app the user can indicate their diet to be of multiple diets.

So now I do a search for all items:filtered:advanced:this items diets intersect with the user’s list of diets: count >= the user’s list of diets:count

What this does is when I intersect the diets of an item with the user’s diets, I filter on only items that have all of the diet’s the user has entered. As stated before, however, this has become a very slow process.

Any ideas on an alternative method would be greatly appreciated.

Perhaps a data restructuring. Instead of marking things with what diet they’re appropriate for, perhaps mark the food items for the ingredients that would make them not correspond to a particular diet, e.g.:

Imagine I’m allergic to gluten, potato starch and lactose. So add a type « Allergen » with field « name », then create the gluent, potato starch and lactose Allergens. Add these allergens to my User’s new field « Allergens list » which is a list of type « Allergen » (not text, I find it’s better in the long term to keep list fields as lists of other data types in case you want to make changes or upgrades).

You now add your food items, so type « Food item », text field « name », for example bread, list field « Contained Allergens » of type « Allergen » has added to it Gluten. Then add a food item « Gluten free bread type 1 » that has in its « Contained Allergens » Potato starch, Gluent free bread type 2 has Lactose and Potato starch, Gluent free bread type 3 has the Allergen « Rice flour » but not Lactose or Potato starch.

Now in your RG you’ve got « Search for Food Items » and your constraints are « Contained Allergens » does not contain « Current User’s Allergens List », so it’ll only show food items that don’t have any of the users allergies in them - for me the only thing I can eat is Gluten Free Bread Type 3, for example.

I know you said diets include vegan etc., so change Allergens to a more appropriate term like “Unwanted ingredient”, it just suited my example for simplicity.

Richard,

Your suggestion makes great sense! I actually think I originally tried this strategy but thought I was being more “advanced” using the ‘advanced’ feature. Gonna go back and use your suggested strategy. Much appreciated!

Hi Richard,

I’m running into an issue on the section

‘Now in your RG you’ve got « Search for Food Items » and your constraints are « Contained Allergens » does not contain « Current User’s Allergens List »’

For some reason, Bubble does not allow me to do a “does not contain” on a list, it has to be a single argument. So if the User is looking for an item that does not contain a list of things, I’m not allowed to do it. Any other suggestions?

01%20PM

Dang, you’re right, we’re back to advanced filters again.

It’d need to be Search for RestaurantItems:filtered - Advanced: Current User’s Allergens List intersects with This RestaurantItem’s Allergens & Diet : count = 0

Comparing lists against lists is a bit of a missing feature set in Bubble. I hope someone else can come up with a better solution that avoids the advanced filters.