<CharlieDigital/> Programming, Politics, and uhh…pineapples

19Dec/11Off

Never Thought of It Like That

Posted by Charles Chen

From the comments section of a CNN article.

16Dec/11Off

Force File Name in SharePoint 2010 Search Results

Posted by Charles Chen

There are a few resources on this for 2007, but I thought I'd add a small update for 2010.

First, start by following the instructions in the links above for the IsDocument property.  You can get to it from the search service administration and it's under Metadata Properties:

Find the IsDocument property in here

Now go to your site and create a new web part page (header, left nav, right body) and call it CustomSearchResults.aspx (or whatever you'd like).  On the right hand side, add a " web part and on the left hand side, add a Refinement Panel web part.

Search web parts available - add Search Core Results and Refinement Panel

Now you need to edit the results web part.

  1. Under the Core Results settings panel, expand the Display Properties sub-panel.
  2. Uncheck Use Location Visualization to enable the Fetched Properties and XSL Editor options.
  3. Modify the Fetched Properties XML string to include <Column Name="Filename"/> (strongly recommend copying the string out and editing it in a text editor).
  4. Click the XSL Editor button to modify the XSL.  Again, I strongly recommend copying the XSL out to a text editor.
  5. Around line 206-207, you should see the following line:
    <xsl:template match="Result">
        <xsl:variable name="id" select="id"/>
  6. Modify it to look like so:
    <xsl:template match="Result">
        <xsl:variable name="id" select="id"/>
        <xsl:variable name="filename" select="filename"/>
        <xsl:variable name="isdocument" select="isdocument"/>
  7. Next, around (new) line 324, you should see the following XSL:
    <xsl:otherwise>
        <a id="{concat($currentId,'_Title')}">
            <xsl:attribute name="href">
                <xsl:value-of  select="$url"/>
            </xsl:attribute>
            <xsl:attribute name="title">
                <xsl:value-of select="title"/>
            </xsl:attribute>
            <xsl:choose>
                <xsl:when test="hithighlightedproperties/HHTitle[. != '']">
                    <xsl:call-template name="HitHighlighting">
                        <xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="title"/>
                </xsl:otherwise>
            </xsl:choose>
        </a>
    </xsl:otherwise>
  8. Update this to the following:
    <xsl:otherwise>
        <a id="{concat($currentId,'_Title')}">
            <xsl:attribute name="href">
                <xsl:value-of  select="$url"/>
            </xsl:attribute>
            <xsl:attribute name="title">
                <xsl:value-of select="title"/>
            </xsl:attribute>
    
            <xsl:if test="$isdocument">
                <xsl:value-of select="filename"/>
            </xsl:if>
            <xsl:if test="not($isdocument)">
                <xsl:choose>
                    <xsl:when test="hithighlightedproperties/HHTitle[. != '']">
                        <xsl:call-template name="HitHighlighting">
                            <xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="title"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </a>
    </xsl:otherwise>

Now hook up your custom search results page by clicking on Site Settings and then Search Settings. In the Site Collection Search Results Page text box, enter the full relative path to your page (including sub-site paths and such).  For example: /sites/site_xyz/pages/mycustomsearchresults.aspx.

That should do it.  Unfortunately, I haven't figured out how to turn on hit highlighting for the file name yet.

Filed under: SharePoint No Comments