More in this section

Forums / Developing with Sitefinity / SearchResult.aspx (Description instead of Snippet)

SearchResult.aspx (Description instead of Snippet)

4 posts, 1 answered
  1. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    09 Sep 2009
    Link to this post
    Hi there

    I mapped to my own SearchResult.aspx and want to make some changes.

    I thought it would make sense to show the Description of a page in SearchResult.aspx

    I tried to change

    <dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd>

    to
    <dd><%#DataBinder.Eval(Container.DataItem, "Description")%></dd>

    Ok it was a not so fortunate guess since it did not work.

    How do I find out what is possible. Title, Snipplet, Url I see in SearchResult.aspx. Looked at the tables in my MS SQL DB but did not find what is beeing accessed.

    QUESTION

    Is there a way to display the page description instead of the Snippet?

    Regareds Markus
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Sep 2009
    Link to this post
    Hi Markus Berchtold,

    You can use the following properties - Title, Snippet, Url, Score.
    There is a way to display a CmsPage description. Below is a sample code:

    <%@ Control Language="C#" %> 
     
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %> 
    <%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls.Admin" 
        TagPrefix="sfSrc" %> 
    <script runat="server"
        public string GetPageDescription(string url) 
        { 
            System.Web.SiteMapNode sNode = System.Web.SiteMap.Provider.FindSiteMapNode(url); 
            return ((Telerik.Cms.Web.CmsSiteMapNode)sNode).CmsPage.Description; 
        } 
    </script> 
     
    <sfWeb:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/Search/searchCommonLayout.css" Media="screen" runat="server" /> 
     
    <h2><asp:Literal ID="ResultsStats" runat="server">Found {0} pages for "{1}" </asp:Literal></h2
     
    <asp:Repeater ID="rptResults" runat="server"
        <HeaderTemplate> 
            <dl class="searchResults"
        </HeaderTemplate> 
        
        <ItemTemplate> 
           <%# GetPageDescription(DataBinder.Eval(Container.DataItem, "Url").ToString()) %> 
            <dt><strong><href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Title")%></a></strong></dt>   
            <dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd
            <dd><em><href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Url")%></a
                        </em></dd>  
        </ItemTemplate>   
     
     
     
         ..... 
            ...... 

    1. We are modifying the SearchResult template.
    2. Then we are creating a custom method where we get pages' description.
    3. Finally we use our method and pass the description through ASP.NET DataBinder.Eval method.

    I hope this helps.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    09 Sep 2009
    Link to this post
    Dear Ivan

    Sensational, tipple A, outstanding Support!!!

    Solution works like a charm! Cut and past and run it.

    Great as usualy.

    PS: Could it make sence for 4.0 to have an option - Show PageDescription or Snippet in the Search. Might be a niche feature :-)

    Regards Markus
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Sep 2009
    Link to this post
    Hello Markus Berchtold,

    Thank you for getting back to me. We will consider possible implementation or at least expose more properties.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
Register for webinar
4 posts, 1 answered