Ordering search results by relevance

Posted by Community Admin on 03-Aug-2018 21:09

Ordering search results by relevance

All Replies

Posted by Community Admin on 27-Mar-2014 00:00

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.

 Dan

Posted by Community Admin on 01-Apr-2014 00:00

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)
        
 
            base.InitializeControls(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
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
 

This thread is closed