title: AngularJS filter tree structure recursively by property
body: <p>I tried multiple things now, but didn't had much success. Let's assume, that I have a list like this:</p>
  
  <pre><code>[
      {
          "name": "Africa",
          "translation": "Afrika",
          "someNum": 87207,
          "countries": [
              {
                  "name": "Algeria",
                  "translation": "Algerien",
                  "someNum": 58020,
                  "countries": null
              },
              {
                  "name": "Morocco",
                  "translation": "Marokko",
                  "someNum": 27314,
                  "countries": null
              },
              {
                  "name": "Libya",
                  "translation": "Lybien",
                  "someNum": 77788,
                  "countries": null
              },
              {
                  "name": "Somalia",
                  "translation": "Somalia",
                  "someNum": 17945,
                  "countries": null
              },
              {
                  "name": "Kenya",
                  "translation": "Kenia",
                  "someNum": 12505,
                  "countries": null
              },
              {
                  "name": "Mauritania",
                  "translation": "Mauretanien",
                  "someNum": 25787,
                  "countries": null
              },
              {
                  "name": "South Africa",
                  "translation": "S\u00fcdafrika",
                  "someNum": 39997,
                  "countries": null
              }
          ]
      },
      {
          "name": "America",
          "translation": "Amerika",
          "someNum": 48450,
          "countries": [
              {
                  "name": "North America",
                  "translation": "Nordamerika",
                  "someNum": 23397,
                  "countries": [
                      {
                          "name": "Canada",
                          "translation": "Kanada",
                          "someNum": 58709,
                          "countries": null
                      },
                      {
                          "name": "USA",
                          "translation": "USA",
                          "someNum": 64725,
                          "countries": [
                              {
                                  "name": "New York",
                                  "translation": "New York",
                                  "someNum": 50202,
                                  "countries": null
                              },
                              {
                                  "name": "California",
                                  "translation": "Kalifornien",
                                  "someNum": 92801,
                                  "countries": [
                                      {
                                          "name": "Los Angeles",
                                          "translation": "Los Angeles",
                                          "someNum": 78283,
                                          "countries": null
                                      },
                                      {
                                          "name": "San Diego",
                                          "translation": "San Diego",
                                          "someNum": 30373,
                                          "countries": null
                                      },
                                      {
                                          "name": "Sacramento",
                                          "translation": "Sacramento",
                                          "someNum": 50721,
                                          "countries": null
                                      },
                                      {
                                          "name": "San Francisco",
                                          "translation": "San Francisco",
                                          "someNum": 65772,
                                          "countries": null
                                      },
                                      {
                                          "name": "Bakersville",
                                          "translation": "Bakersville",
                                          "someNum": 20390,
                                          "countries": null
                                      }
                                  ]
                              },
                              {
                                  "name": "Lousiana",
                                  "translation": "Lousiana",
                                  "someNum": 26245,
                                  "countries": null
                              },
                              {
                                  "name": "Texas",
                                  "translation": "Texas",
                                  "someNum": 57720,
                                  "countries": null
                              },
                              {
                                  "name": "Nevada",
                                  "translation": "Nevada",
                                  "someNum": 41399,
                                  "countries": null
                              },
                              {
                                  "name": "Montana",
                                  "translation": "Montana",
                                  "someNum": 97221,
                                  "countries": null
                              },
                              {
                                  "name": "Virginia",
                                  "translation": "Virginia",
                                  "someNum": 64101,
                                  "countries": null
                              }
                          ]
                      }
                  ]
              },
              {
                  "name": "Middle America",
                  "translation": "Mittelamerika",
                  "someNum": 60813,
                  "countries": [
                      {
                          "name": "Mexico",
                          "translation": "Mexiko",
                          "someNum": 97953,
                          "countries": null
                      },
                      {
                          "name": "Honduras",
                          "translation": "Honduras",
                          "someNum": 40591,
                          "countries": null
                      },
                      {
                          "name": "Guatemala",
                          "translation": "Guatemala",
                          "someNum": 41592,
                          "countries": null
                      }
                  ]
              },
              {
                  "name": "South America",
                  "translation": "S\u00fcdamerika",
                  "someNum": 61507,
                  "countries": null
              }
          ]
      },
      {
          "name": "Asia",
          "translation": "Asien",
          "someNum": 38179,
          "countries": [
              {
                  "name": "China",
                  "translation": "China",
                  "someNum": 47266
              },
              {
                  "name": "India",
                  "translation": "Indien",
                  "someNum": 33424,
                  "countries": null
              },
              {
                  "name": "Malaysia",
                  "translation": "Malaysia",
                  "someNum": 38010,
                  "countries": null
              },
              {
                  "name": "Thailand",
                  "translation": "Thailand",
                  "someNum": 41356,
                  "countries": null
              },
              {
                  "name": "Vietnam",
                  "translation": "Vietnam",
                  "someNum": 79489,
                  "countries": null
              },
              {
                  "name": "Singapore",
                  "translation": "Singapur",
                  "someNum": 53176,
                  "countries": null
              },
              {
                  "name": "Indonesia",
                  "translation": "Indonesien",
                  "someNum": 89895,
                  "countries": null
              },
              {
                  "name": "Mongolia",
                  "translation": "Mongolei",
                  "someNum": 42783,
                  "countries": null
              }
          ]
      },
      {
          "name": "Europe",
          "translation": "Europa",
          "someNum": 84723,
          "countries": [
              {
                  "name": "North",
                  "translation": "Nord",
                  "someNum": 16833,
                  "countries": [
                      {
                          "name": "Norway",
                          "translation": "Norwegen",
                          "someNum": 11817,
                          "countries": null
                      },
                      {
                          "name": "Sweden",
                          "translation": "Schweden",
                          "someNum": 38210,
                          "countries": null
                      },
                      {
                          "name": "Finland",
                          "translation": "Finnland",
                          "someNum": 10669,
                          "countries": null
                      }
                  ]
              },
              {
                  "name": "East",
                  "translation": "Ost",
                  "someNum": 28434,
                  "countries": [
                      {
                          "name": "Romania",
                          "translation": "Rum\u00e4nien",
                          "someNum": 45122,
                          "countries": null
                      },
                      {
                          "name": "Bulgaria",
                          "translation": "Bulgarien",
                          "countries": null
                      },
                      {
                          "name": "Poland",
                          "translation": "Polen",
                          "someNum": 84183,
                          "countries": null
                      }
                  ]
              },
              {
                  "name": "South",
                  "translation": "S\u00fcd",
                  "someNum": 71856,
                  "countries": [
                      {
                          "name": "Italy",
                          "translation": "Italien",
                          "someNum": 76406,
                          "countries": null
                      },
                      {
                          "name": "Greece",
                          "translation": "Griechenland",
                          "someNum": 18189,
                          "countries": null
                      },
                      {
                          "name": "Spain",
                          "translation": "Spanien",
                          "someNum": 36148,
                          "countries": null
                      }
                  ]
              },
              {
                  "name": "West",
                  "translation": "West",
                  "someNum": 33487,
                  "countries": [
                      {
                          "name": "France",
                          "translation": "Frankreich",
                          "someNum": 72622,
                          "countries": null
                      },
                      {
                          "name": "England",
                          "translation": "England",
                          "someNum": 51927,
                          "countries": null
                      },
                      {
                          "name": "Portugal",
                          "translation": "Portugal",
                          "someNum": 25502,
                          "countries": null
                      }
                  ]
              }
          ]
      },
      {
          "name": "Oceania",
          "translation": "Ozeanien",
          "someNum": 69844,
          "countries": [
              {
                  "name": "Australia",
                  "translation": "Australien",
                  "someNum": 17211,
                  "countries": null
              },
              {
                  "name": "New Zealand",
                  "translation": "Neuseeland",
                  "someNum": 87401,
                  "countries": null
              }
          ]
      },
      {
          "name": "Arctica",
          "translation": "Arktis",
          "someNum": 67183,
          "countries": null
      },
      {
          "name": "Antarctica",
          "translation": "Antarktis",
          "someNum": 92518,
          "countries": null
      }
  ]
  </code></pre>
  
  <p>What I try to achieve, is to find all parents and/or children, matching my search criteria while keeping the whole tree intact.</p>
  
  <p>Let's say I am searching for <code>Australia</code> as value of the property <code>name</code>. The expected result would be:</p>
  
  <pre><code>- Oceania
  -- Australia
  </code></pre>
  
  <p>But what I get is</p>
  
  <pre><code>- Oceania
  -- Australia
  -- New Zealand
  </code></pre>
  
  <p>Another example: I am searching for <code>Kalifornien</code> as value of the property <code>translation</code>. The expected result would be:</p>
  
  <pre><code>- America
  -- North America
  --- USA
  ---- California
  ----- Bakersville
  ----- San Diego
  ----- Sacramento
  ----- San Francisco
  ----- Los Angeles
  </code></pre>
  
  <p>But the actual result is absolutely not, what you'd expect.</p>
  
  <p>So the main problem I am experiencing is, that the original <em>Angular</em> filter doesn't process children correctly.</p>
  
  <p>I have set up a Plunker to demonstrate the problem: <a href="https://plnkr.co/edit/3FavpC8XB3hTvT94fZli?p=preview" rel="nofollow noreferrer">https://plnkr.co/edit/3FavpC8XB3hTvT94fZli?p=preview</a></p>
  
  <p>I can also change the format of the <em>JSON</em> data, if that makes it easier to achieve a proper filtering.</p>
  
  <p>EDIT:</p>
  
  <p>I've had partial success: <a href="https://plnkr.co/edit/lDoUK3?p=preview" rel="nofollow noreferrer">https://plnkr.co/edit/lDoUK3?p=preview</a></p>
  
  <p>There's just one problem left. If I search (for example) for California, the objects from the <code>countries</code> property of the object with the name California are missing. So the last item is California (which is good so far), but I also need Bakersville, San Diego &amp; co. under it.</p>