Friday, November 21, 2008

Want to know how to change MOSS search results sort order?


Some of you may have seen my post on how to add rating field to MOSS search results,

Since than I have had several customers that wanted to allow their users to sort the search resutls by that rating field, and not by the relevance / date (Even though I explained that this will break the MOSS search relevance mechanism).

Be that as it may, after searching the web - I managed to locate several "free tools" that does that, but I was determined to find a more simple solution that did not involve downloading/executing any out side code on my server.

Finally, I found that this can be done by a very simple change to the XSL of the main search results body web part (the same one we modified in the previouse post).

Simply replace this statement in the XSL:
<xsl:apply-templates />

With this one:
<xsl:sort select="rating"/>

You might want to allow the user to sort by relevance / date and rating, and not only rating. In that case you should use the actions web part above the main search resutls web part and add a new option there to specify when it should sort by rating and not do it hard-coded in the results XSL web part.

Hope this helps,
Shai Petel,