More in this section
Blogs RSS feed

Customizing Sitefinity SearchResults - displaying Product thumbnails and other Content type-specific data

by Boyan Barnev
Many of you have requested assistance in delivering various custom functionality in the Sitefinity SearchResults widgets.

From displaying the Page's description, showing custom messages depending on the type of the item, to displaying Product thumbnails.

By default the SearchResults widget operates with an IResultSet containing objects of type IDocument - these are the item representations in the Sitefinity search index, and are the same for all Sitefinity content, thus only general properties can be persisted.

Each IDocument carries the information for the item's ContentType  in the contain the "ContentType" field where you can obtain the correct information what kind of item you're dealing with.

Once you've resolved the type, you can then operate with this type's specific properties, however you first need to get the actual item (remember what you've been working with so far is the Lucene document, not the Sitefinity item). 

This is done by obtaining the item's ID. By default the field name where the original Sitefinity content ID is stored inside each Lucene document varies depending on how the particular module has configured its inbound pipe. The unified concept that we have adopted is that all Content types will use the "OriginalItemId" field.

Once we have information about the ContentType  and the OriginalItemId this allows us to determine which content manager we need to call, and which Id to pass, in order to retrieve the actual item. Form then on operating with the item is just as with any item of that type - you can get its properties and use them depending on your specific use case scenario.

So for the SearchResults widget we can easily create an external template based on the default one, that  will allow us to use code-behind, subscribe to the ResultsListItemDataBound  event in the template code-behind and do something like:

using System;
using System.Linq;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Ecommerce.Catalog.Model;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Ecommerce.Catalog;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Services.Search.Data;
using Telerik.Sitefinity.Utilities.TypeConverters;
using DotNetImageControl = System.Web.UI.WebControls.Image;
namespace SitefinityWebApp.CustomTemplates
    public partial class SearchResultsProducts : System.Web.UI.UserControl
        protected void Page_Load(object sender, EventArgs e)
            this.resultsList.ItemDataBound += ResultsListItemDataBound;
            this.catalogManager = CatalogManager.GetManager();
            this.libMan = LibrariesManager.GetManager();
            this.pageMan = PageManager.GetManager();
        void ResultsListItemDataBound(object sender, RepeaterItemEventArgs e)
            var myitem = e.Item.DataItem as IDocument;
            if (myitem != null)
                //You need to check for the type of the item you have gotten in your search results
                var type = myitem.GetValue("ContentType");
                //Documents enter the index with an Id field
                if (TypeResolutionService.ResolveType(type) == typeof(Document))
                    var docItem = libMan.GetDocument(new Guid(myitem.GetValue("Id")));
                    var path = docItem.FilePath;
                //Pages get in the index with OriginalItemId field
                //Here's how you can display a page property in your search results
                if (TypeResolutionService.ResolveType(type) == typeof(PageNode))
                    var ID = new Guid(myitem.GetValue("OriginalItemId"));
                    //you can now get the item with its manager and access its properties,
                    //since you'll be working with an object of the correct type
                    //for example:
                    var page = pageMan.GetPageNode(ID);
                    if (page != null)
                        //check if the PageNode has PageData
                        if (page.Page != null)
                            //now you can simply get a control from your template and set the value to it,
                            //so it can be displayed
                            var literalControl = e.Item.FindControl("pageDescriptionLiteral") as Literal;
                            literalControl.Text = page.Page.Description;
                //Products, and Content items also enter the index with OriginalItemId field
                if (TypeResolutionService.ResolveType(type) == typeof(Product))
                    var ID = new Guid(myitem.GetValue("OriginalItemId"));
                    //get the control that will display our data on the template
                    var image = e.Item.FindControl("productThumbnail") as DotNetImageControl;
                    //get the actual Product item
                    var product = CatalogManager.GetManager().GetProduct(ID);
                    if (product != null)
                        //ste the property value to the control so it will be displayed on the frontend
                        image.ImageUrl = product.PrimaryImageUrl;
        private CatalogManager catalogManager;
        private LibrariesManager libMan;
        private PageManager pageMan;


For your convenience I'm attaching an archive of the control template above to this post.

In conclusion, you've probably realized that this post just scratches the surface on the amount of modifications that can be done when customizing your search results, hope it helps you achieve your desired functionality.


Leave a comment
  1. Justin Feb 05, 2013
    I have been trying to get this functionality into our search results, however I seem to have missed something as I receive this error message:

    Exception Details: System.ArgumentException: There is no field with the specified name.
    Source Error:
    Line 34: var productItem = catalogManager.GetProduct(myitem.GetValue("OriginalContentId"));

    we are running this version of Sitefinity: Sitefinity 5.2.3800.0

    Any help would be very grateful.

  2. Boyan Feb 21, 2013

    Hey Justin,

    Thank you for letting us know of the problem with he provided sample. The post information and the sample have been updated to properly reflect the correct property name.

  3. Vishika Jan 14, 2014
    Hello I have tried your code above and I have an error message as below:
    Error parsing the template

    I am actually using Sitefinity 6.3.  I would be grateful if you can help me out of it please

    Thank you
  4. Arnold Nov 22, 2017
    Excellent and very exciting site. Love to watch. Keep Rocking. happy new year 2018 messages
  5. Arnold Dec 09, 2017
    Phenomenal article. Extremely fascinating to peruse. I truly love to peruse such a pleasant article. Much obliged! continue shaking.  holm law group san diego

    Leave a comment