Try our conversational search powered by Generative AI!

Per Nergård
Oct 24, 2013
  3804
(1 votes)

Let editors set pages to always be on top in search result (SearchDataSource not Find)

I got a question from a customer if it was possible to specify certain pages that would always be displayed on top of the search results list disregarding that other pages might have higher ranking.

So I added a checkbox property named “GivePriorityInSearch” to my page types. And ticked it for two pages see image below from Alloy demo site when searching for the word “plan”.

1_UnFiltered

Then I created a simple filter.

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using EPiServer.Core; 7 using EPiServer.Filters; 8 9 namespace Nergard.EPi.Filters 10 { 11 public class PrioritySearchFilter : IPageFilter 12 { 13 #region IPageFilter Members 14 15 public void Filter(EPiServer.Core.PageDataCollection pages) 16 { 17 var priorityPdc = new PageDataCollection(); 18 var normalPdc = new PageDataCollection(); 19 20 for (var x = 0; x <= pages.Count - 1; x++) 21 { 22 if (pages[x]["GivePriorityInSearch"] != null) 23 priorityPdc.Add(pages[x]); 24 else 25 normalPdc.Add(pages[x]); 26 } 27 28 priorityPdc.Add(normalPdc); 29 30 for (var x = 0; x <= pages.Count - 1; x++) 31 { 32 pages[x] = priorityPdc[x]; 33 } 34 35 } 36 37 public void Filter(object sender, FilterEventArgs e) 38 { 39 this.Filter(e.Pages); 40 } 41 42 public bool ShouldFilter(EPiServer.Core.PageData page) 43 { 44 throw new NotImplementedException(); 45 } 46 47 #endregion 48 } 49 }

After that I hooked it up to the SearchDataSource in the search page.

 

1 SearchDataSource.Filter += SearchDataSource_Filter; 2 3 void SearchDataSource_Filter(object sender, Filters.FilterEventArgs e) 4 { 5 new Nergard.EPi.Filters.PrioritySearchFilter().Filter(e.Pages); 6 }

And now searching for plan gives the following result.

 

2_Filtered

Oct 24, 2013

Comments

Eric
Eric Oct 24, 2013 01:32 PM

Nice feature.

Arild Henrichsen
Arild Henrichsen Oct 25, 2013 12:48 PM

Nice solution Per. Sticky search results might be especially useful on sites with lots of similar content (e.g. an archive of statistics published each year) where old content will compete with the new content for rankings. In those cases, the site owner will want to make sure the updated content is given priority.

Please login to comment.
Latest blogs
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog