EPiServer Search Functionality for Blocks

EPiServer Search Functionality for Blocks

While working in a project, a client decided that the search functionality using EPiServer search needed to take into account also the information inside the blocks. Unfortunately, EPiServer search does not implement this functionality by default (EPiServer Find does), so we decided to search about some possible solutions and we found and interesting post from Jeron and even better a nice nuget package that implemented that post in a neat and easy way. So I decided to write this post to explain how to use this package and warning you about some possible hiccups you could go through while implementing it.


First, we will install the nuget package using the nuget package management console with this command: Install-Package EPi.Libraries.BlockSearch
Take int account the CMS version you are working on. For instance, versions 4.x.x work in EPiServer CMS 10, versions 5.x.x work in EPiServer CMS 11.

After installation, you should add the search text property to your base page, if you do not have one, I highly recommend you to add one to your project.

    [SiteContentType(GUID = "98448299-51bd-45a9-8d68-7dcdfee0a031", AvailableInEditMode = false)]
    public class SitePage : PageData
        public virtual string SearchText { get; set; }

Just as a reminder, this property should be added to the base page, not base block, if not you will index several times the information of the blocks instead of the information of the page and blocks as one.

Now that we have the base property set, we can decide which properties of a block can be indexed. All that information is going to be send to the Search Text property of the page, if the block is being used inside that page. To define a searchable property we use the Searchable attribute.

    public class BaseContentSlideBlock : BlockData
        [Display(GroupName = SystemTabNames.Content, Order = 2003)]
        public virtual string Title { get; set; }

        [Display(GroupName = SystemTabNames.Content, Order = 2004)]
        public virtual XhtmlString Description { get; set; }

In the class above, both fields Title and Description will be indexed in the block.

And that is all. The next time you publish the page with this block inside a content area, it will index the information of the page and the block together as one. I hope it will help someone and as always keep learning !!!

Written by:

Jorge Cardenas

Developer with several years of experience who is passionate about technology and how to solve problems through it.

View All Posts

Leave a Reply