Saturday, February 2, 2008

Modifying the Search results URL in sharepoint 2007 searchresults.aspx

How to remove something (the port) from the URL as returned in the search results (searchresults.aspx):

Starting with the Infrastructure update, the following behavior can be encountered when searching for people:
The port (usually 80) is appended to the URL of the location for each result, resulting in error for all the internet facing personal sites.
For example, imagine you published your my site location in Alternate Access Mappings at : http://mysites.mydomain.com to be accessed from the intranet and https://mysites.mydomain.com to be accessed from the internet.

When you are searching for a user when logged on from the internet side of things, you will receive the results pointing to https://mysite.mydomain.com:80/Person.aspx?GUID... which will throw an error upon accessing (page not found).

If you want to overcome the issue (eg, you are looking for a quick fix) here's what you can do:

Go to your search center with tabs and search for something, just to get to the people results page.
Edit the page and modify the People Search Core Results web-part.
Click on the XSL Editor button to get to the XSL style sheet applied to the resultset.
The URL for each result is under the following section:














<!-- This template is called for each result -->

<xsl:template match="All_Results/Result">
<xsl:variable name="id" select="id"/>
.....
here ,

replace <xsl:variable name ="url" select ="url"/>
line with:


<xsl:variable name ="temp" select ="url"/>
<!-- We put the url value from the resultset in temp variable -->

<xsl:variable name="url">
<!-- This will be the value used in the xsl from now on in this section as $url -->

<xsl:choose>
<xsl:when test="contains($temp,':80')">
<!--We check temp variable for the occurrences of string :80-->
<xsl:value-of select ="concat(substring-before($temp,':80'),substring-after($temp,':80'))"/>

<!--We remove from temp variable the occurrences of string :80-->
</xsl:when>

<xsl:otherwise>
<xsl:value-of select ="$temp"/>
<!--If we did not find the :80 we will retain the default value (url) as defined above-->

</xsl:otherwise>
</xsl:choose>
</xsl:variable>

....

So from now on, wherever we will use $url we will have the translated version of the url returned in the resultset
eg. for https://mysite.mydomain.com:80/person.aspx?GUID....... the result would be https://mysite.mydomain.com/Person.aspx?GUID.......

Of course you will also need to play with the Search High Confidence Results web Part to Edit it accordingly.
The place where you need to replace the url is :

<xsl:template match="All_Results/HighConfidenceResults/Result">
<xsl:if test="$DisplayHC = 'True' and $IsFirstPage = 'True'" >
<xsl:variable name="prefix">IMNRC('</xsl:variable>
<xsl:variable name="suffix">')
</xsl:variable>
<xsl:variable name="url" select="url"/>
<xsl:variable name="id" select="id"/>

replace <xsl:variable name ="url" select ="url"/> line as above

Here are some additional references on how to edit, and tune the search results to fit your company needs:

http://msdn.microsoft.com/en-us/library/ms584121.aspx
http://msdn.microsoft.com/en-us/library/ms256069(VS.85).aspx