November Happy Hour will be moved to Thursday December 5th.

Per Nergård
Oct 24, 2013
  3908
(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
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog