How to Display the Site Title and Site URL in Search Results

August 03, 2011

Recently I was restyling the search results, and one of the expectations was to display a hyperlink to the site of origin of the result.

Adding the site title of the returned results is very easy, this can be retrieved from the metadata property "SiteTitle". The web URL is a bit more difficult. My first thought was to check the crawled properties, but there is no reference for the web URL, only a reference for the site collection URL called: "ows_SPSiteURL".

My second thought was to some XSL manipulation, and this was the best approach.

The final result will be:

Search Result with Site Reference

Search Result with Site Reference

The things I did to establish this were:

  1. Adding Site Title column references to the fetched properties of the Core Result Web Part.
  2. Editing the XSLT from the Core Result Web Part.

In the following sections I will go deeper into the two steps.

Adding column references (Fetched Properties)

Fetched Properties are used to let SharePoint know which metadata should be retrieved for each result.

The column that needs to be added is: "SiteTitle".

To add these columns go to your search result page or the page where you are using the core search web part.

  • Turn the page in edit mode;
  • Edit the "Search Core Results" web part;
  • Open the "Display Properties" section;
    Display Properties Section

    Display Properties Section

  • Add the following column to the "Fetched Properties";
    <Column Name=" SiteTitle "/>
  • Click "Ok".

The full "Fetched Properties" XML is the following:

Search result XSL styling

Now that the" SiteTitle" column is added as to the Fetched Properties, you can edit the Search result style.

  • Edit the "Search Core Results" web part;
  • Under the "Display Properties" section, click on the "XSL Editor" button;
    XSL Editor

    XSL Editor

  • Copy the content of the XSL Editor to the text editor of your choice;
  • Add the following two XSL templates before the </xsl:stylesheet> closing tag;
  • The next step is to add the following piece of code somewhere inside the "Results" template.
  • Click "OK" and save the page.


Each search result contains the site hyperlink (depending on the location in the result template).

Final Result

Final Result

This solution only works on items and documents. When sites are returned as results, the site url gets broken. To fix this you could check if the result "contentclass" is not equal to "STS_Site".