Display contents of page subfolder inside search result

sam j asked on June 30, 2019 16:28

I'm currently getting details of a page in search results, i need to display contents of the page subfolder(child menu item) in the search results i'm getting. Say for example, i have a page named "Page One" and a folder under it called "feature"(or menu item), and then multiple page menu items under that "feature" folder, i need to display the name and contents of the form, for those page menu items. "Page One">"Feature"(folder)>"feature1, feature2"(multiple page menu item). If you look at the image, i want to display form contents inside "feature 1" form, which is the new page menu item i created under "Feature".

Please See image: Image Text

Image Text

Here's my code so far: <%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>

<section class="archived-product new-product-li" data-product-cat="<%# CMS.DocumentEngine.DocumentHelper.GetDocuments().Published(true).Where("NodeID = " + GetSearchValue("NodeParentId").ToString()).FirstOrDefault().GetValue("DocumentName").ToString() %>">

<%# IsLast()
+ ""
//+ "
//+ "<button class=\"cta-button cta-button--black cta-block__cta\">Show More Results"
//+ ""
"" %>

Recent Answers

Mike Wills answered on July 1, 2019 08:08

Hi Sam,

Another way to do this is to add custom properties to the search index. You can actually add custom properties to the index, like Feature Name and Feature Description, even though they are not fields of "Page One".

The easiest way to do this is to subscribe to the DocumentEvents.GetContent.Execute event. When handling the event, check to see if the page is one for which you need the custom Feature Name and Feature Description properties. If it is, get the values from the child nodes, and add them to the index using SearchDocument.Add. It would look something like this:

private static void Document_GetContent_Execute(object sender, DocumentSearchEventArgs e)
    var parentPage = e.Node;
    // Insert code to retrieve the feature name and feature description 
    // from the child nodes
    // Add the custom properties to the index
    e.SearchDocument.Add("FeatureName", featureName, true, false);
    e.SearchDocument.Add("FeatureDescription", FeatureDescription, true, false);

Then in the search results, you would be able to get both of these values using the GetSearchValue method. This will be easier and much more performant.

There's a great article about on how to add custom content to the search index by Kristian Bortnik. Check it out here:



0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 1, 2019 14:21

Use the out of the box search index and webpart. Set your search index to be least restrictive and get "everything". Then in your webpart configure the path to be more restrictive using a macro expression checking maybe the node level and node classname then setting the path to ./featured-folder/% No need to write custom code for this.

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on July 1, 2019 18:13

Brenden, if using a macro expression in the search results, wouldn't that be creating a SQL round-trip for every item in the search results?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 1, 2019 18:29


Assuming it's using Smart Search, it will use the Lucene index which is not SQL. So that being said, it should be a very quick to apply that path filter.

If you're referring to the macro syntax, no a simple macro like:

if(CurrentDocument.NodeAliasPath.StartsWith("/page-1") && CurrentDocument.NodeLevel == 1 ) { "./featured-folder/%'; } else { "" }

Should not create any SQL calls because the CurrentDocument context/object is filled when the page loads and the other conditions are simple string/integer compaisons.

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on July 1, 2019 19:32

Hi Brenden,

This sounds inderesting. Is this what you're saying? When the parent page is encountered in the search results, query the Lucene index for the child content from the search transformation, and get the Feature Name and Feature Description field values from those child items? If I'm hearing you right, wouldn't that would require a custom transformation or macro method that would receive the child path determined by the example macro. The method would query the index for the child items, so that the transformation could access the field values of the child items?



0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 1, 2019 20:05

No I'm saying if your search index contains the whole content tree and you use that index on a global search page (/search) as well as on another page (/products/brand-1), when you land on the /products/brand-1 page, you can set the path of the search results webpart to be based on that current path and everything below it.

We have a few sites setup like this for a document library with categories and other taxonomy setup on them. For example a school district site which publishes all of their meeting minutes. Each meeting minute page contains a name, description, asset link, and taxonomy is placed in a location below /district/meeting-minutes. The search index is specific to the /district/meeting-minutes path and there are sub-pages below meeting-minutes for simple categorization.

For instance:

All pages below /district/meeting-minutes inherit the template from the meeting-minutes page. The only difference is the macro for the path, which further filters out the base dataset of meeting minutes based on the current path.

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on July 1, 2019 21:04 (last edited on July 1, 2019 21:04)

Oh, I think I see. I was interpreting Sam’s question as needing to display “Feature Name” and “Feature Description” as if its part of “Page 1’s” content. So, if there was a search that only returned “Page 1”, it would still display “Feature Name” and “Feature Description” as if that child content is part of “Page 1”.

For example, as if the “Services” content of each of the search result items in this screenshot came from child nodes of each parent page.

Image Text

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.