Ordering search results by relevance
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
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;