3 Replies Latest reply on May 8, 2017 8:59 AM by Kenji Hashimoto

    Find Element by name from hierarchy

    Paurav Joshi

      Hello All,

       

      Question has one tweak from discussion title .

      I have hierachy as follows:

      A  -> B -> C -> D

         |-> E -> C -> F

       

      I want to find all child elements under element name C, i.e. D and F. and in one query call only. D and F have different templates with some part of it in common, like searching on template name * common * will give you D and F.

      I can make it under 2 different calls via AFElement.FindElements method. Tried using AFElementSearch and unable to crack the que.

       

      All suggestions are invited .

       

      Thanks,

      Paurav Joshi

        • Re: Find Element by name from hierarchy
          Rick Davin

          Hi Paurav,

           

          Interesting question.  We might need David Hearn  to chime in on this one.  I do suggest an edit to your hierarchy:

           

          A  -> B -> C1 -> D

            |-> E -> C2 -> F

           

          Do you only want D and F to be returned?  What if C1 had 3 child elements (that is, D has 2 siblings) and C2 has 5 child elements?  Do you still only want to see D and F, or do you want all child elements to C1 and C2?

           

          What was your earlier attempt with AFElementSearch ?

           

          Is it impractical to suggest decorating D and F with their own element category?

           

          Keep in mind that depending upon how specialized you want your final results to be that sometimes that means it can't be done with one call.

            • Re: Find Element by name from hierarchy
              Paurav Joshi

              Hi Rick,

               

              Thanks for reply.

              I do suggest an edit to your hierarchy:

               

              A -> B -> C1 -> D

              |-> E -> C2 -> F

              C has reference to other applications PI as well as non-PI, so we like to avoid that.

               

              Do you only want D and F to be returned?  What if C1 had 3 child elements (that is, D has 2 siblings) and C2 has 5 child elements?  Do you still only want to see D and F, or do you want all child elements to C1 and C2?

               

              I want all immediate child elements of C1 and C2.

              What was your earlier attempt with AFElementSearch ?

              My attempt was like
              AFElementSearch search = new AFElementSearch(myAFDB, "FindChildElements", @"Root:'A' ");

              The only problem I stuck here is that I can't specify parent parameter as it is not available per search parameter I saw here .

               

              Is it impractical to suggest decorating D and F with their own element category?

              Difficulty is that we are making hierarchy of Geographywise as per client requirement, and for this alternative too many changes have to be done.

              This is not impractical to say, we reserved it as last option to weigh against 2 calls.

               

              Thanks,

              Paurav Joshi

                • Re: Find Element by name from hierarchy
                  Kenji Hashimoto

                  At least I don't know that we can get child elements by search method.

                  Search method returns elements that hit the search criteria.

                  So as you may already know, we need to create 2 calls.

                  For example,

                  AFElementSearch search = new AFElementSearch(db, "FindChildElements", @"Root:'A' Name:'C' ");
                  foreach(AFElement item in search.FindElements(fullLoad: true))
                  {
                      AFElements childelms = item.Elements;
                      foreach(AFElement elm in childelms)
                      {
                          Console.WriteLine("  ChildElement {0}", elm.Name);
                      }
                  }
                  
                  

                  It returns element 'C' 's child elements.

                  I also vote to set 'Category' for search these child elements. (I can understand it is difficult for you to achieve it though)

                  Will you have performance issue if you will use 2 calls?