+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / hide descrription from search results in Sitefinity

hide descrription from search results in Sitefinity

3 posts, 0 answered
  1. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    01 Nov 2010
    Link to this post
    Hi Guys,

    I am at a loss as to when the "..." appears in the search results and when it doesn't. For consistency sake, I would prefer that the description appears as per all other results but sometimes this does not seem to happen and I get the "..."

    If I cannot have a description in all my results I would like to hide the "..." altogether. Can you please tell me how I would go about this?

    Thanks,
    James
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Nov 2010
    Link to this post
    Hello James,

    Below is a sample code that illustrates how to remove the <strong>...</storng> search results separator. You should modify Sitefinity/Admin/ControlTemplates/Search/SearchResults.ascx

    <%@ Control Language="C#" AutoEventWireup="true" %>
       
       
    <script type="text/C#" runat="server">
       
        protected void Page_Load(object sender, EventArgs e)
        {
            this.rptResults.ItemDataBound += new RepeaterItemEventHandler(rptResults_ItemDataBound);
               
        }
       
        void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
       
                Literal lit = (Literal)e.Item.FindControl("Literal1");
                Telerik.Search.Engine.ResultItem resultITem = e.Item.DataItem as Telerik.Search.Engine.ResultItem;
                string value = resultITem.Snippet;
                string toRemove = " <strong>...</strong> ";
                if (value.StartsWith(toRemove))
                {
                    int length = value.Length - toRemove.Length;
                    string value1 = value.Substring(value.IndexOf(toRemove) + toRemove.Length, length);
                    resultITem.Snippet = value1;
                    lit.Text = value1;
                       
                      
                }     
            }
        }
       
    </script>
       
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls.Admin"
        TagPrefix="sfSrc" %>
       
    <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>
              
            <dt><strong><a href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Title")%></a></strong></dt>
            <%--<dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd>--%>
            <dd><asp:Literal ID="Literal1" runat="server"></asp:Literal></dd>
            <dd><em><a href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Url")%></a>
                        </em></dd>
        </ItemTemplate>
        <FooterTemplate>
            </dl>
        </FooterTemplate>
    </asp:Repeater>
       
    <sfWeb:Pager ID="pager1" runat="server">
        <LayoutTemplate>
             <asp:Repeater ID="PageRepeaterLinkButton" runat="server">
                <HeaderTemplate>
                    <ol class="sf_pager">
                    <li><asp:LinkButton ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:LinkButton></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:LinkButton ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:LinkButton ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:LinkButton></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
            <asp:Repeater ID="PageRepeaterHyperLink" runat="server">
                <HeaderTemplate>
                    <ol class="sf_pager">
                    <li><asp:HyperLink ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:HyperLink></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:HyperLink ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:HyperLink></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
        </LayoutTemplate>
    </sfWeb:Pager>

    If you need more complex way to remove the search results separator you should use RegularExpression to match all values from the snippet from where the dots come from.

    You have to comment the DataItem.Snippet and put the Literal control

    <dd><asp:Literal ID="Literal1" runat="server"></asp:Literal></dd>


     in the template. The idea here is that you will use the literal to show the text

    resultITem.Snippet = value1;
    lit.Text = value1;

     instead of

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




    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    01 Nov 2010
    Link to this post
    Thanks Ivan. I will try that then.

    Cheers
Register for webinar
3 posts, 0 answered