Friday, December 6, 2013

SharePoint 2010 Search - View Properties Link w/ folder and case support - Federated

  • You have SharePoint 2010 Server Standard or Enterprise
  • SharePoint search results provide a link to the document, but no other links
    • Often times a user has to copy and paste the document library url into the address bar and then search for the document in the library to view the properties or kick off a workflow.  This is extremely inconvenient.
  • You would also like a link to the document's View Item (DispForm.aspx) form
  • You would also like a link to the document's Document Library
  • You would like to configure this at the Search Service level so that the links appear in any search center in the farm utilizing the Search Service and also on the OSSSearchResults pages
  • Utilizing code from the following blogs

  • Configure the Search Service in Central Administration as follows
    • Xslt variables and parameters are case sensitive
    • Make sure instructions are followed exactly as written
  • Create 2 managed properties (Metadata Properties in Search Service Application) after your sites have been crawled
    • basic4
      • map to basic:4(text)

        • You have to page to the right after selecting the "basic" group.  It does not show up on the first screen when searching for the crawled properties.  You cannot use the free-text search filter to find this item.
    • listitemid
      • map to ows_ID(integer)
    • Configure Federated Locations in Search Service Application.
      • Click "Local Search Results"
      • Expand "Display Information"
      • Modify the following "Core Search Results Display Metadata" sections
        • Uncheck "Use Default Formatting"
        • Add the following columns to the "Properties" window

          <Column Name="ServerRedirectedURL"/>

          <Column Name="listitemid"/>
          <Column Name="basic4"/>
      • Copy the contents of the XSL into a text editor like Visual Studio or Notepad  
        • Find the IsDesignMode parameter and modify as follows

          <xsl:param name="IsDesignMode">True</xsl:param>

          <xsl:param name="listitemid" />
          <xsl:param name="basic4" />
      • Find the DisplaySize template call and modify as follows

        <xsl:call-template name="DisplaySize">
        <xsl:with-param name="size" select="size" />

        <xsl:call-template name="DisplayViewPropertiesLink">
        <xsl:with-param name="basicFour" select="basic4" />
        <xsl:with-param name="itemUrl" select="url" />
        <xsl:with-param name="siteUrl" select="sitename" />
        <xsl:with-param name="listItemId" select="listitemid" />
        <xsl:with-param name="contentclass" select="contentclass" />

        <img style="display:none;" alt="" src="/_layouts/images/blank.gif"/>

      • Find the end of Stylesheet tag at bottom of document and modify as follows

        <!-- A custom template to display a link to view the properties for a document -->
        <xsl:template name="DisplayViewPropertiesLink">
        <xsl:param name="basicFour" /> <xsl:param name="itemUrl" /> <xsl:param name="siteUrl" /> <xsl:param name="listItemId" /> <xsl:param name="contentclass" /> <!-- Variables to convert siteUrl to lower -->
        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
        <xsl:if test="$contentclass='STS_ListItem_DocumentLibrary'">
        <xsl:when test="contains($basicFour,'http')">
        <xsl:variable name="library" select="substring-before(concat(substring-after(translate($siteUrl, $uppercase, $smallcase), concat(translate($basicFour, $uppercase, $smallcase), '/')), '/'), '/')" />
        <xsl:variable name="viewPropUrl" select="concat($basicFour, '/', $library, '/Forms/DispForm.aspx?id=', $listItemId)" />
        - <a href="{$viewPropUrl}">View Properties</a>
        <xsl:variable name="docLibLoc" select="substring-before(substring-after($itemUrl, concat($siteUrl, '/')), '/')" />
        <xsl:variable name="viewPropUrl" select="concat($siteUrl, '/', $docLibLoc, '/Forms/DispForm.aspx?id=', $listItemId)" />
        - <a href="{$viewPropUrl}">View Properties</a>
        - <a href="{$siteUrl}">
        View Library

        <!-- End of Stylesheet -->

      • Copy the contents of the text file into the "Properties:" textbox, replacing all existing text
      • Hit OK to save the changes
    • You may need to reset the index and run a full crawl to get everything working afterwards
      • Sometimes the Search Centers cache the old XSLT for awhile, so the index reset and possibly an app pool recycle may get it to refresh from the federated location.  Or toggling the Core Results web part on the search center page can work as well.