Displaying Social Ratings in Search Results

Posted Monday, October 4, 2010 5:27 PM by CoreyRoth

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.

DocumentLibrarySocialRatings

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.

AverageRatingCrawledProperty

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. 

AverageRatingManagedProperty

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.

AverageRating>=3

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.

AverageRatingFederatedLocation

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.

AverageRatingXSL

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.

AverageRatingSearchResults

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.

Comments

# Twitter Trackbacks for Displaying Social Ratings in Search Results - Corey Roth [dotnetmafia.com] on Topsy.com

Pingback from  Twitter Trackbacks for                 Displaying Social Ratings in Search Results - Corey Roth         [dotnetmafia.com]        on Topsy.com

# re: Displaying Social Ratings in Search Results

Tuesday, October 5, 2010 10:01 AM by Todd Carter

Looks like you beat me on the publish. Funny how we were both working on the same topic...Check out my post: todd-carter.com/.../Pimp-Document-Ratings-within-SharePoint-Search-Results.aspx

# re: Displaying Social Ratings in Search Results

Tuesday, October 5, 2010 10:11 AM by CoreyRoth

@ToddCarter Wow, what are the odds.  You implemented the stars in the search results.  Very nice.

# re: Displaying Social Ratings in Search Results

Tuesday, March 29, 2011 7:05 AM by Eric

Can the rating be sorted in search results?

# re: Displaying Social Ratings in Search Results

Monday, April 4, 2011 1:19 PM by CoreyRoth

@Eric Not with SharePoint Search.  I think it should be possible with FAST, but I would have to test it.

# re: Displaying Social Ratings in Search Results

Monday, April 23, 2012 2:03 PM by Dhaval Shah

Leave a Comment

(required)
(required)
(optional)
(required)