Modify CMS.Root.SmartSearchResults transformation to handle structured Pages in results

Robert Srigley asked on February 14, 2019 14:44

I am using the Web Part Control Id - SmartSearchDialogWithResults. My Seach index contains both Pages and WebPagesCrawl types. The Page Filter Page types = custom.tbPolicy;CMS.MenuItem;CMS.File The Tranformations = CMS.Root.SmartSearchResults

The search results are displaying both CMS.MenuItem and custom.tbPolicy search results which is fine. If the result is of type CMS.MenuItem, the Title hyperlink and the Content are fine and the link works if you click on it to take you to the page.

If the search results are displaying my structured page custome.tbPolicy type, the Title is the alias path or name path to a page. The content is the GUID of the attachement file. The custom.tbpolicy is a structured page that has a file upload field contained in it.

In the page type Search Definition the Title field is set to PolicyTitle and the ContentField is set to Policy File.

How do I augment the transformation code to check what page type is being displayed and adjust the output code accordingly? Specficially Search results title and Search results content code blocks?

This is the default code.

<%-- Search result title --%>
<a style="font-weight: 700;" href='<%# SearchResultUrl() %>'> <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.Base.Web.UI.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "", "")%>   
<%-- Search result content --%>
<%#SearchHighlight(HTMLHelper.HTMLEncode(TextHelper.LimitLength(HttpUtility.HtmlDecode(HTMLHelper.StripTags(CMS.Base.Web.UI.ControlsHelper.RemoveDynamicControls(GetSearchedContent(DataHelper.GetNotEmpty(Eval("Content"), ""))), false, true, " ", "@", "")), 280, "...")), "<span style='background-color: #FEFF8F'>", "")%>
<%-- Relevance, URL, Creattion --%>
Relevance

                <div title="Relevance: <%# Convert.ToInt32(ValidationHelper.GetDouble(Eval(" Score"), 0) * 100) %>
                    %"
                    style="width: 50px; border: solid 1px #aaaaaa; margin-top: 10px; margin-right: 6px; margin-left:3px; float: left; color: #0000ff; font-size: 2pt; line-height: 4px; height: 4px;">
                    <div style='<%# "background-color:#a7d3a7;width:" + Convert.ToString(Convert.ToInt32(ValidationHelper.GetDouble(Eval("Score"), 0) * 50)) + "px;height:4px;line-height: 4px;" %>'>
                    </div>
                </div>
            </div>
        </div>
        <%-- URL --%>
        <span style="color: #EA961C">
            <div class="row">
                <div class="col-sm-12 search-relevance">
                    <div>
                        Page Path: <%# SearchHighlight(SearchResultUrl(),"<strong>","</strong>")%>
                    </div>
                </div>
            </div>
        </span>
        <%-- Creation --%>
        <div class="row">
            <div class="col-sm-12 search-relevance">
                <div>
                    Created On: <span style="color: #2B3E85; font-size: 9pt; margin-left:3px;">
                        <%# GetDateTimeString(ValidationHelper.GetDateTime(Eval("Created"), DateTimeHelper.ZERO_TIME), true) %>
                    </span>
                </div>

            </div>
        </div>
        <hr />
    </div>

If there is any more in depth documentation on this subject, can you provide the links.

Thank you.

Correct Answer

Brenden Kehren answered on February 14, 2019 16:00

Use something like:

<asp:PlaceHolder ID="ph1" runat="server Visible='<%# GetSearchValue("ClassName").ToString().ToLower() == "custom.tbpolicy" %>'>
// do your work if it's a tbPolicy page type
</asp:PlaceHolder>
0 votesVote for this answer Unmark Correct answer

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