From the Blogosphere
Displaying Social Ratings in Search Results
I absolutely love the new social ratings site columns that we can easily add to existing SharePoint 2010 document libraries
By: Corey Roth
Oct. 4, 2010 06:27 PM
I absolutely love the new social ratings site columns that we can easily add to existing SharePoint 2010 document libraries. It gives such an easy way for end users to rate documents in an interface they are probably already familiar with because of iTunes.
I got to thinking. Seeing these social ratings in my search results sure would be useful. It would also be nice to be able to query them. How do we do that? We use managed properties of course. I did some digging and found out that there isn’t a managed property already out there for this so we need to create one. We know the actual name of the site column is AverageRating (the display name is Rating (0-5)). This means that once we have performed a crawl, we should have a crawled property called ows_AverageRating. Sure enough if you look in your crawled properties, it is there. In my screenshot below, you see the result of me mapping it later. Yours shouldn’t have anything listed under Mapped To yet.
Create a new managed property called AverageRating (or whatever you want to call it). Choose a data type of Decimal and pick the ows_AverageRating column from the list.
Now you need to go back to your content sources page and do a full crawl. When your crawl completes, we can now test and see if our new property works. Go to your Search Center and try the query below.
If all goes well, you should see some search results for documents that have more at least three stars. Note that there are no spaces in that query at all. If it doesn’t work, you may not have any documents rated yet or you recently applied ratings and you need to wait for the timer job to run.
This tells us that we can write queries on our managed property, but we want to actually see them in our results as well. For this we need to customize the properties we return in search results as well as the XSLT. We can do this in either CoreResutlsWebPart or on the Local Search Results federated location. I am going to edit the federated location. Go down to Core Search Results Display Metadata under Display Information and edit the Properties. Start by adding the following inside the Columns element.
<Column Name="AverageRating" />
This tells Enterprise Search to include this column in the results.
We then need to edit the XSL. Finding the right spot can be somewhat tricky, but it’s not too difficult. A good spot for your new rating is in the srch-Metadata2 div. This is where it already displays things like author, file size, and tags. Simply add the following right before the blank.gif reference.
Rating: <xsl:value-of select="averagerating"/>
It should look like this when you’re done.
When you finish editing your XSL, save your changes, wait a minute or so and then go and try your query again. You should now see search results similar to the ones below. Notice the Rating listed for each result.
This gives us a decent representation of what we can do with social ratings in search results. Wouldn’t it be nice if we could sort by this new managed property? Sorry, you’ve got to buy FAST for that or write your own search results screen using the QueryManager class. Even without sorting though, i think this adds a lot of value to your search results.
The next step would be to display actual stars instead of a numerical representation. I’ll continue to work on something on how to do that. In the mean time, someone smarter than me at XSL may be able to provide us all an answer. :) If you have one, I’d love to see it.
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
SYS-CON Featured Whitepapers
Most Read This Week