I'm trying to understand how to search within a tree of objects. I've looked at various search tutorials but I can't figure it out.
Basically, I've got a structure in which a node can have any number of child nodes, which in turn can have any number of child nodes. (I do understand that they can only be nested up to 100 deep.)
Consider a document with this structure:
{
"title": "food",
"children": [
{
"title": "fruit",
"children": [
{
"title": "red",
"children": [
{ "title": "cherry", "children":[] },
{ "title": "apple", "children":[] },
{ "title": "raspberry", "children":[] },
{ "title": "pomegranate", "children":[] }
]
},
{
"title": "yellow",
"children": [
{ "title": "banana", "children":[] }
]
}
]
},
{
"title": "spices",
"children": [
{ "title": "paprika", "children":[] },
{
"title": "pepper",
"children": [
{ "title": "java", "children":[] },
{ "title": "matico", "children":[] }
]
}
]
}
]
}
Now, suppose I want to find that node that has the title "matico". I just want to return that node, not the entire structure. How is that done?