Search Results issue

Posted by Community Admin on 04-Aug-2018 07:31

Search Results issue

All Replies

Posted by Community Admin on 12-Jan-2012 00:00

Hi,

In our website search results page we have to display result status as below

Displaying results 1-10 of 31

We tried using 
<sitefinity:SitefinityLabel id="resultsStats" runat="server"  Text=" Displaying results 0 - 1 of 2">
</sitefinity:SitefinityLabel>
But we unable achieve this. Could you please suggest us how to implement without any custom cs code. 

Thanks,
Karnan


Posted by Community Admin on 16-Jan-2012 00:00

Hi Karnan,

If you want to achieve the desired result you may need to implement custom logic for a custom search results control. The template for the search results template can be found in the SDK, however in the code behind you will need to implement a logic for the pager to get all items displayed on the current page out of all items that are found.

Kind regards,
Victor Velev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 18-Jan-2012 00:00

Hi Victor Velev,

Thank you so much, but still we expect this in the next release. Since it is commonly used across all sites.

Thanks,
Karnan

Posted by Community Admin on 23-Jan-2012 00:00

Hi Karman,

We will consider your request, however it is hard to tell whether such custom implementation will go in the next release, as we are few weeks away from releasing. Thank you for suggestion.

Regards,
Victor Velev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-May-2013 00:00

Hi Victor Velev,

Can you share with us some code, in order to achieve that?

Thanks!

Posted by Community Admin on 15-May-2013 00:00

Hello guys,

 Here's one way to achieve this scenario. Create a custom SearchResults widget. It must be a class that inherits from the default one. In it we will replace the default template with a custom one by overriding the layoutTemplatePath property to point to our custom template (which should be an Embedded resource). Since it's an embedded resouce we also need to register a virtual path, like in the attached image.

public class CustomSearchResults : SearchResults
    
 
        public CustomSearchResults()
        
            this.AllowPaging = true;
            this.ItemsPerPage = 10;
            this.LayoutTemplatePath = CustomSearchResults.layoutTemplatePath;
            this.SearchFields = new[] "Title", "Content" ;
            this.HighlightedFields = new[] "Title", "Content" ;
        
        protected internal virtual Label ItemsPerPageLabel
        
            get
            
                return this.Container.GetControl<Label>("ItemsPerPageLabel", false);
            
        
 
           protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
           
               base.InitializeControls(container);
               if (!string.IsNullOrEmpty(this.Query))
               
                   int totalItems = 0;
                   var skip = 0;
                   var take = this.ItemsPerPage;
 
                   var searcher = this.GetSearcher();
                   var result = searcher.Search(this.Query, this.IndexCatalogue, skip, take, out totalItems);
 
                   var itemsOnPage = this.ItemsPerPage.ToString();
                  // var searchResultsCount = this.ResultsStats;
                   var itemsCount = result.ToList().Count.ToString();
                   this.ItemsPerPageLabel.Text = string.Format("Displaying results 1-0 of 1", itemsOnPage, itemsCount);
                
               
           
           public static readonly string layoutTemplatePath = "~/VPP/SitefinityWebApp.Templates.CustomSearchResulttemp.ascx";
         
 
    

Since the number of items per page is exposed in a public property called ItemsPerPage, we're going to use it to construct the text as per your requirement - Displaying results 1-10 of 20. Out custom template is an ascx file,where we add a label control in which we will display our new message:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomSearchResulttemp.ascx.cs" Inherits="SitefinityWebApp.Templates.CustomSearchResulttemp" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity.Search.Impl" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
 
<sfSearch:SearchBox ID="topSearchBox" runat="server" />
 
<sitefinity:SitefinityLabel id="resultsStats" runat="server" WrapperTagName="p" CssClass="sfsearchResultStatistics" Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" />
<asp:Label runat="server" ID="ItemsPerPageLabel" />
<asp:Repeater ID="resultsList" runat="server">
    <HeaderTemplate>
        <dl class="sfsearchResultsWrp sfsearchReultTitleSnippetUrl">
    </HeaderTemplate>
    <ItemTemplate>
        <dt class="sfsearchResultTitle"><a id="A1" runat="server" href='<%# Eval("Link")%>'><%# Eval("Title") %></a></dt
        <dd class="sfsearchResultSnippet"><%# Eval("Summary")%></dd>
        <dd class="sfsearchResultUrl"><a id="A2" runat="server"  href='<%# Eval("Link")%>'><%# Eval("Link")%></a></dd>
        <dd class="sfsearchResultHighLighter"><%# Eval("HighLighterResult")%></dd>
    </ItemTemplate>
    <FooterTemplate>
        </dl>
    </FooterTemplate>
</asp:Repeater>
<sitefinity:Pager ID="pager" runat="server" />
<sfSearch:SearchBox ID="bottomSearchBox" runat="server" />

This is how we get the label from the template in our custom widget:
protected internal virtual Label ItemsPerPageLabel
        
            get
            
                return this.Container.GetControl<Label>("ItemsPerPageLabel", false);
            
        

Then on initializeControls of the new widget we construct the message from the search results items count, and the itemsPerpage property. 

Hope this helps!

Regards,
Jen Peleva
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed