How to Sort Search Result By Title, PublicationData, LastUpd

Posted by Community Admin on 04-Aug-2018 06:40

How to Sort Search Result By Title, PublicationData, LastUpdated, etc..

All Replies

Posted by Community Admin on 04-Jun-2013 00:00

I just want to sort search result by Title, PublicationData, LastUpdated etc.. Please see the attached image for more details. It has separate drop-down for select search field. I just want to sort the search result when selecting an item from the drop-down. 

Posted by Community Admin on 15-Oct-2014 00:00

how I can do to make me order the search results based on the outcome golf products?

Posted by Community Admin on 20-Oct-2014 00:00

Hello,

The approach for achieving the desired result is to make a custom SearchResults widget inheriting from the default one and using its template, which we will customize to add the widgets to display the required data. I have made a sample for you, where I use the base logic for the searching and only add the logic for displaying the desired data and sorting. Basically, you could get the fields of the result items and filter them, or use an item OriginalContentId to query it. The easiest way to get the items count is to get the number of items bound to the repeater, since there is no property set for this and the variable is 'hidden' in the base InitializeControls.
Result Video.

Code:

Copy Code
public class CustomSearch : SearchResults
    
        public override string LayoutTemplatePath
        
            get
            
                return CustomSearch.CustomSearchLayoutTemplatePath;
            
            set
            
                base.LayoutTemplatePath = value;
            
        
 
        public Label TitleLabel
        
            get
            
                return this.Container.GetControl<Label>("Title", true);
            
        
 
        public Label PagesLabel
        
            get
            
                return this.Container.GetControl<Label>("Pages", true);
            
        
 
        public Button Sort
        
            get
            
                return this.Container.GetControl<Button>("Sort", true);
            
        
 
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        
            base.InitializeControls(container);
 
            this.Sort.Click += Sort_Click;
            if (!string.IsNullOrWhiteSpace(this.Query))
            
                this.TitleLabel.Text = string.Format("You searched for '0'", this.Query);               
            
            var data = this.ResultsList.DataSource as IEnumerable<object>;
            if (data != null)
            
                var count = data.Count();
                this.PagesLabel.Text = string.Format("0 Results Found", count.ToString());
                if (count > 0)
                
                    this.Sort.Visible = true;
                
            
        
 
        void Sort_Click(object sender, EventArgs e)
        
            var data = this.ResultsList.DataSource as IEnumerable<IDocument>;
            data = data.OrderByDescending(t => t.GetValue("Title"));
            this.ResultsList.DataSource = data;
            this.ResultsList.DataBind();
        
 
        private static string CustomSearchLayoutTemplatePath = "~/Widgets/CustomSearch/CustomSearchTemplate.ascx";
    

Template:
Copy Code
<%@ Control Language="C#" %>
<%@ 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" />
 
 
<asp:Label ID="Title" runat="server" Text=""></asp:Label>
<asp:Label ID="Pages" runat="server" Text=""></asp:Label>
 
<asp:Button ID="Sort" runat="server" Text="Sort" Visible="false" />
 
<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" />

I hope you find this sample useful. You can use it as a starter to achieve your requirement.

Regards,
Vassil Vassilev
Telerik
 
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 20-Oct-2014 00:00

Thank you .

But my code is based on the following link

www.sitefinity.com/.../customizing-sitefinity-searchresults---displaying-product-thumbnails-and-other-content-type-specific-data

 
any idea as being able to order?

 

 

This thread is closed