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 Jan 18, 2018
    In this great pattern of things you actually secure  a B+ with regard to hard work. Where exactly you lost me was first in your specifics. You know,  people say, details make or break the argument.. And that couldn’t be much more true right here. Having said that, let me reveal to you precisely what did give good results. Your writing is actually highly powerful and that is probably the reason why I am taking the effort in order to comment. I do not really make it a regular habit of doing that. Second, even though I can see a leaps in reasoning you come up with, I am not necessarily confident of exactly how you seem to unite the points which produce the actual final result. For now I will, no doubt subscribe to your issue but hope in the near future you connect the dots better. neet 2018 form
  5. chris Jan 20, 2018
    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often. forskolin standardized to 20
  6. ronijames Jan 21, 2018
    No more s***. All posts of this qaulity from now on go here
  7. chris Jan 22, 2018
    The data you have posted is exceptionally helpful. The destinations you have alluded was great. A debt of gratitude is in order for sharing..  Natalia Starr Videos
  8. chris Jan 23, 2018
    I high value this post. It's elusive the great from the awful once in a while, yet I think you've nailed it! would you brain overhauling your web journal with more data?  Free Download
  9. chris Jan 31, 2018
    A debt of gratitude is in order for setting aside an ideal opportunity to talk about this, I feel unequivocally about it and affection adapting more on this subject. On the off chance that conceivable, as you pick up ability, would you psyche overhauling your website with additional data? It is greatly useful for m get free stuff online now
  10. best breast enhancement pills Feb 01, 2018
    My brother recommended I may like this web site. He was entirely right. This publish actually made my day. You can not consider just how so much time I had spent for this information! Thank you! best breast enhancement pills
  11. roni Feb 03, 2018
    This will be a terrific blog, would you be interested in doing an interview about just how you developed it? If so e-mail me! dog training youtube
  12. TriboTEX Feb 06, 2018
  13. roni Feb 19, 2018
    superb  post. Ne’er knew this,  appreciate it for letting me know. buy ultimate ecom mastery
  14. roni Feb 23, 2018
    I  likewise   conceive  thus, perfectly written   post! . gdpr courses london

    Leave a comment