Custom Data Type for Search Index

I’ve tried searching this topic but haven’t found anything that seems to definitively answer my question. Hopefully asking directly will yield the answers I need!

I’m building an app where during sign up, the User will select a main ‘Category’ and up to three ‘Sub-Categories’ to attribute to their profile.

So for instance, the first dropdown would have Categories like these:
Hats
Coats
Shoes
Accessories

Let’s assume the User selects ‘Hats’. The sub-categories for Hats would look like this:
Dad Hats
Fitted Hats
FlexFit Hats
Snapback Hats

What is the best way to structure these elements and attribute them to the User’s profile so that when conducting a search for Hats, and then let’s say more specifically Dad Hats, the search would return this User as the result?

I hope I’m not asking too much, but this is my last major hurdle. Thanks in advance!

Hi callisdusxi,
welcome to Bubble.

My approach here would be:
Combine categories and subcategories as one data type and connect them with a parent child relationship.
Whenever categories are selected, save them to the user and save that user to the categories list of users to make it easy to see all users who have selected a certain category.

In steps:

  1. Create a datatype categories. Have the data field text (e.g. hats, dad hats), have the data field level (eg 0,1,2) have the data field parent (type category) and the data field children (a list of categories). Also add the field: users with this category, a list of users.

  2. When you create a category such as hats coats shoes, have it lvl 0.

  3. To create subcategories: Have a repeating group with do a search for categories lvl = 0. Inside every cell have an input to add the subcategories text and a button to create subcategories. When you create a subcategory: make it type category but lvl 1, with the current cell as parent. Also make changes to the parent, to add the new category to its list of children. In my case this button is in a group



    So to clarify, categories and subcategories are the same data type but have different levels and categories do not have parents.

  4. For the data type user add a field selected category, a category and a field selected categories: list of categories.

5.For the 1st dropdown: as source have do a search for categories where lvl = 0. When the user selects a category and clicks confirm, on the confirm buttons workflow: make changes to the user so user’s selected category = that category. Make changes to the selected category to add that user to the categories list of users.

  1. For the 2nd dropdown: as source have current users selected categorys’ children
    2019-09-14%2015_42_01-Todolisttool%20_%20Bubble%20Editor
    When the button confirm is clicked, add that subcategory to the users list of selected categories. Also make changes to that subcategory to add the user to that subcategories list of users.


    With this info in a repeating group you can now have
    do a search for categories where lvl = 1.
    In this RG have another RG with data type users: current cell’s categories list of users. Here you can display all users with that subcategory.

hope this helps. Feel free to pm me if you have more questions or would like to hop on a quick call.

happy bubbling,
Julius

1 Like
1 Like

Wow. Thank you for such a thorough walk through. I’ll look to implement this solution tonight. Many, many thanks!