Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1444 posts 1855 karma points
    Dec 29, 2014 @ 18:30
    Gordon Saxby
    0

    Page constructed from multiple child nodes can't show preview

    I am working on a site where each page is constructed from the page node itself as well as any number of child nodes that represent content "rows".

    I have got the search working by adding the content of the child "row" nodes to the "contents" combined field in ezSearchBootstrapper.cs.

    What I can't figure out at the moment, is how to present content from a "row" node as the preview text. Currently, the preview text is empty or doesn't include the search term (if the search term is found on a "row" child node).

    Any ideas would be most welcome!!

  • Gordon Saxby 1444 posts 1855 karma points
    Dec 30, 2014 @ 19:20
    Gordon Saxby
    0

    Any ideas? I have got the search working, I just need to figure out how to show the contextual content!? Can I get to the "contents" field which is the combination of all fields, including those from child nodes.

  • keilo 568 posts 1023 karma points
    Jan 14, 2015 @ 10:04
    keilo
    0

    Hi Gordon

    Can you share the change you have done on ezSearchBootstrapper.cs to make it include the child nodes?

    Does the search works as intended (i.e. search result shows the container page (where the term is located in its child)) ?

    cheers

  • Gordon Saxby 1444 posts 1855 karma points
    Jan 14, 2015 @ 13:23
    Gordon Saxby
    0

    It will probably depend on your exact requirements, but this is what I did for my project.

    I added the following code into "OnGatheringNodeData" in ezSearchBootstrapper.cs

                if (e.IndexType == IndexTypes.Content) {
    var node = new Node(e.NodeId);

    foreach (var rowItem in node.ChildrenAsList.Where(t => t.template == 0))
    {
    combinedFields = AddAllFields(combinedFields, rowItem.PropertiesAsList);
    }
    }

    I put it right after the foreach loop that fills "combinedFields" and before "e.Fields.Add("contents", combinedFields.ToString())".

    This is AddAllFields()

            private StringBuilder AddAllFields(StringBuilder combinedFields, System.Collections.Generic.List<umbraco.interfaces.IProperty> properties)
    {
    foreach (var property in properties)
    {
    if (property.Value != null)
    {
    combinedFields.AppendLine(property.Value.ToString());
    }
    }
    return combinedFields;
    }

    By default, the search results page / code will not display pages without a template assigned, so no changes were needed there. The only issue is that the text displayed underneath each search result may not contain the actual search term. In fact, there may not be any text at all. That is still to be looked at ;-)

     

Please Sign in or register to post replies

Write your reply to:

Draft