Thursday, April 15, 2010

Display SharePoint 2010 ratings in search results XSL

I had a requirement to show the ratings(new feature in Sharepoint 2010) for all items that are returned in search results.

The crawled property that we have to use to get to the ratings is ows_AverageRating. You first need to create a metadata property like AverageRating that maps to the crawled property ows_AverageRating(decimal) to be able to display rating in search results. After adding the property, make sure that you run a full crawl so that the indexer picks up all the ratings.

After adding the property and performing a full crawl, we can use the below XSL to display rating for each item in search results.



 
   
  
    
  
  
    
  
  
    
  
   
   

 
   No Rating
   





 
 
 
   
   
  
  
   
 


Note: I have used 2 icons ratings_halfstar_blue.png and ratings_star_blue.png which are free to download. Make sure that you upload them some where and adjust the paths accordingly.

Ref: http://blogs.technet.com/speschka/archive/2009/10/28/using-the-new-sharepoint-2010-ratings-feature-in-search.aspx

6 comments:

  1. Hi Chaitu,

    I am trying to create a managed metadata to map to ows_AverageRating, but I cannot find ows_AverageRating in the crawled properties list (while performing "add mapping").

    Any ideas? Thanks.

    Best regards,
    raihan

    ReplyDelete
  2. You will need to activate Enterprise Keywords/rating in the list/library settings first. Then create an item in the list/lirary and then the crawler will know that it needs to crawl the ows_AverageRating.

    ReplyDelete
  3. Please show a full example of your code. This is confusing and doesn't seem to work as outlined in either blog. You can't expect us all to know where to put this code :(

    ReplyDelete
  4. Hi,

    You will need to have some knowledge of SharePoint Search XSLT in order to be able to use this XSLT. Once you are able to figure out how the SharePoint Search XSLT works, it would be clear to you how this code works. If you still experience issues, please write back.. I will see what I can do

    ReplyDelete
  5. imad 13 Apr 2011 1:35 AM # I have followed the steps, i am the SP administrator, site owner and super user, yet, all i see if "no ratings" everywhere.

    what would be the issue?

    thanks

    Imad

    even in advanced search, i specify that i want items with ratings =5, it returns the result for me, however, labeled as "no rating"

    ReplyDelete
  6. Depending on how the ratings timer job is configured to run, you will see a delay in SP synchronizing the ratings.. Run the rating timer job manually and see if that helps..

    ReplyDelete