Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom Maton 387 posts 660 karma points
    Jul 17, 2012 @ 14:06
    Tom Maton
    0

    Examine search - get children in results

    Hi All,

    I've implemented an Examine search and retrieving my results, but I also what to get the child nodes of the results I've found.

    So for example my content is like so (node alias in brackets):

    UK (Country)
    -- England (Country)
    ---- Location 1 (Location)
    ---- Location 2 (location)
    ---- Location 3 (Location)
    --Wales (Country)
    ---- Location 1 (Location)
    ---- Location 2 (Location)
    --Scotland (Country)
    ---- Location 1 (Location)

    My query is like so:

     var query = searchCritera.Field("nodeTypeAlias", nodeType).And().Field("nodeName", nodeName).Compile();

     

    So if I did a search for Country = England I get that node back no problem, but I also want to get all locations under England at the same time in the Examine search.

    But I also want to be able to search Country = UK I would want to get everything under that.

    Any ideas greatly appreciated.

    Thanks,
    Tom

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jul 17, 2012 @ 14:50
    Hendy Racher
    1

    Hi Tom,

    How about when indexing a (Location) node, you also also add the details of all it's ancestor (Country) nodes, (so that this data is available with that item).

    public class IndexLocations : ApplicationBase
    {
      public IndexLocations()
      {
        ExamineManager.Instance.IndexProviderCollection["indexerName"].GatheringNodeData += new EventHandler(this.IndexLocations_GatheringNodeData);
      }
    
      private void IndexLocations_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
      {
        Node indexingNode = uQuery.GetNode(e.NodeId);
        if (indexingNode != null && indexingNode.NodeTypeAlias == "Location")
        {
          StringBuilder countries = new StringBuilder();
    
          foreach(Node countryNode in indexingNode.GetAcnestorNodes().Where(x => x.nodeTypeAlias == "Country"))
          {
             countries.Append(countryNode.Text + " "); // or the details you want to search that country on
          }
    
          e.Fields.Add("Countries", countries.ToString().TrimEnd());
        }
      }
    }
    

     

    HTH,

    Hendy

     

  • Tom Maton 387 posts 660 karma points
    Jul 19, 2012 @ 10:26
    Tom Maton
    0

    Hey Hendy,

    Cheers bud, that works a treat.

    Thanks,

    Tom

Please Sign in or register to post replies

Write your reply to:

Draft