CMS 6: PageType Search Provider

blog header image

Inspired by Magnus’ excellent blog post earlier today I just had to throw together a little search provider of my own. And yes, it really was as simple as he made it seem. In my little example here I wanted to make the PageTypes search-able, so I made a provider to search through those. It did take me 10 min to make, but in all fairness to Magnus’ claim that it can be done in 5, I spend the first 5 minutes actually reading his post :-)

Here are the steps I took:

  • I added references to EPiServer.Shell and System.ComponentModel.Composition
  • I made sure my project (in this case I just used the Public Templates project) assembly was listed in the episerver.shell plug-in assemblies in web.config
  • I wrote the implementation you see below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Shell.Search.Contracts;
using EPiServer.DataAbstraction;
using System.ComponentModel.Composition;
 
namespace EPiServer.SearchProviders
{
    [Export(typeof(ISearchProvider))]
    public class PageTypeSearchProvider : ISearchProvider
    {
        #region ISearchProvider Members
 
        public string Area
        {
            get { return "CMS"; }
        }
 
        public string Category
        {
            get { return "Page Types"; }
        }
 
        public IEnumerable<SearchResult> Search(Query query)
        {
            //Lookup page type based on name
            var rt = from p in PageType.List()
                     where p.Name.ToLower().Contains(query.SearchQuery.ToLower())
                     orderby p.Name
                     select new SearchResult(
                         EPiServer.UriSupport.ResolveUrlFromUIBySettings("Admin/EditPageType.aspx")
                         +"?typeId=" + p.ID.ToString(), p.Name, p.Description);
            return rt.Take(query.MaxResults);
        }
 
        #endregion
    }
}

The only problem is that the link I generate to editing the page-types doesn’t open in the right frame-context. I’m working on figuring that one out :-)

Recent posts