Home | Blog | Screencasts | Projects
# Wednesday, February 24, 2010

One of the nice things about SharePoint 2010 is that the developers did not seal the classes of the common web parts, so we can now create our own web parts that derive and extent the functionality. I thought it might be fun to play with the search refiner web part that I blogged about recently, so I took the standard search refiner and plugged in the excellent tag cloud implementation from codeplex.

 

So instead of rendering the normal list of refiners with counts against them, it instead uses the count to determine the tag cloud size:

VisualTagCloudRefiner

 

 

The code for creating this is below:


public class VisualRefiner : Microsoft.Office.Server.Search.WebControls.RefinementWebPart
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            var xmlDoc = this._RefinementManager.GetRefinementXml();

            var filters = xmlDoc.GetElementsByTagName("Filter");

            Dictionary tags = new Dictionary();
            foreach (XmlNode filter in filters)
            {
                var valueNode = filter.SelectSingleNode("Value");
                var countNode = filter.SelectSingleNode("Count");
                if (countNode != null && valueNode != null)
                {
                    if (!string.IsNullOrEmpty(countNode.InnerText))
                    {
                        int tagCount;

                        if (int.TryParse(countNode.InnerText, out tagCount))
                        {
                            if (!tags.ContainsKey(valueNode.InnerText))
                            {
                                tags.Add(valueNode.InnerText, tagCount);
                            }
                        }
                    }
                }
            }

	    //TODO: Make the url useable
            var tagCloud = new TagCloud(tags, 
		new TagCloudGenerationRules { Order = TagCloudOrder.Random, TagUrlFormatString = "/pages/search.aspx" });

            writer.Write(tagCloud);
            
        }
        
    }




I’m not saying that this view adds any more value than the standard refiner view, in the screenshot above it actually looks pretty poor.

The interesting part about the web part is the use of the refinement manager, it returns the results of the refinement process in xml form. This is really powerful, it means that we could potentially create some really creative visuals around the search results. It will be interesting to watch the community to see what types of variations come out.

Statistics
Total Posts: 191
This Year: 0
This Month: 0
This Week: 0
Comments: 41