Hi Power Thunkers!
This is an advanced question… I need to create a generic search function running over a Firebase database, which returns from a initial path a list with all the results found below this path.
The search can be of 2 types: search for a value or a bucket.
For example let’s say I search for the value “John Wick”. A possible result in the list would be:
/CUSTOMERS/0017/NAME
/INVOICES/3465/CUSTOMER_NAME
/HELPDESK/TICKETS/542/RESPOND_TO
Or let’s say I want to fetch all buckets that are equal to “2022-05-10”, the result would be something like this:
/LOGS/2022-05-10
/SCHEDULE/2022-05-10
/SALES/2022-05-10
The list must contain all occurrences no matter how deep they may be in the Firebase structure. So we must do a complete reading of the entire structure below the origin point looking for all possible matches, and inserting in the result list.
I thought of several ways to do this, but as far as I know I’ll have to use a recursive search function, to go down in the structure from the first to the last level of each key, using “get object proprieties” of cloud variables, and them use the “for each” or “count” loop blocks to traverse the data of each bucket, to finally store in a list the results that match the defined search criteria.
However, I ran into the issue that the variables “J” or “I” of the loop blocks are unique during the entire app session, so each time the recursive function is called, the variables lose their previous content when back, so we have an erratic behavior of the function.
Another approach I thought of doing this implementation would be to read all structure data coming from Firebase into a big JSON text, and look for all the occurrences inside, but in this case I have no idea how to retrieve the ascending structure of the data found.
Does anyone have any ideas on how to make something like this work?
Any ideas on how to implement this function would be most welcome!
Regards,