Try Now
More in this section

Forums / General Discussions / Ordering search results by relevance

Ordering search results by relevance

2 posts, 0 answered
  1. Dan
    Dan avatar
    1 posts
    16 Jan 2014
    27 Mar 2014
    Link to this post

    We are working on a site that requires news items to appear in the search results, but the client would prefer that the news items appear below any other content pages in the search results.

    I've been digging through the Advanced Settings of 'Search' and 'News' and am not finding any way to impact that sort order.

     Any help would be appreciated.


  2. Junior Dominguez
    Junior Dominguez avatar
    115 posts
    03 Oct 2016
    01 Apr 2014
    Link to this post
    Hi Dan,

    An easy approach may consist on  extending the SearchResults control. The overridden InitializeControls method may look like this:

    public class CustomSearchResults : SearchResults
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
                if (!SystemManager.IsDesignMode)
                    var resultsList = base.ResultsList.DataSource as IEnumerable<IDocument>;
                    resultsList = resultsList.ToList();
                    var newsDocuments = resultsList.Where(d => d.GetValue("ContentType").ToString() == typeof(NewsItem).FullName).ToList();
                    (resultsList as List<IDocument>).RemoveAll(d => d.GetValue("ContentType").ToString() == typeof(NewsItem).FullName);
                    (resultsList as List<IDocument>).InsertRange(0, newsDocuments);
                    ResultsList.DataSource = resultsList;

    More details in this video

    Kind Regards,
    Junior Dominguez
    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
2 posts, 0 answered