locked
Have search results display the filename of a word doc, instead of the Title Metadata RRS feed

  • Question

  • Hi,

    Im currently implementing a campus wide search service, based on MOSS 2007. It obviously indexes a lot of Word documents.

    If the word document has no value in its 'Title' metadata (properties of the document) then the filename is displayed in the search results page, and if a title value is present then this is shown instead. However, whoever created our word templates put the value SU_REPORT into the title value of the template and so ALL of our documents now have this in (yes stupid i know!) Nobody every changes these, so we have a lot of docs that when displayed in the search results show a meaningless name of SU_REPORT

    So my question is, can  i modify the behaviour of search so that if the title is blank OR the title = "SU_report" then the filename is displayed instead?

    I'm guessing that this is done either via the XSLT to control the display in the Core Results WebPart, or maybe it can be done at the metadata level by disconnecting the title property (i'd rather not do this because it is very occasionally useful!)

    Any advice greatfully receieved

    James Watts
    Wednesday, April 22, 2009 11:27 PM

Answers

  • * Modify search core web parts
    * In the "Results Query Options" update the Selected Columns property by adding a new column: <Column Name="Filename"/>

    * Under Data View Properties (of search core web part toolpart) edit the XSL by clicking on "XSL Editor..." button:
        *  Do a find for "<xsl:variable name="id" select="id" />, it should be in the Result template
         * Under the id variable, add a new variable:  <xsl:variable name="filename" select="filename" />   (yes, filename should be lowercase)
         * A few lines down you should see <span class="srch-Title">, update that section to the xsl below:

    <span class="srch-Title">
       <a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
    <xsl:if test="$isdocument &#61; 1">
    <xsl:value-of select="filename"/>
    </xsl:if>
    <xsl:if test="$isdocument &#61; 0">
        <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>
    • Proposed as answer by ryandale56 Thursday, June 18, 2009 6:41 PM
    • Marked as answer by JWatts Saturday, June 20, 2009 6:06 PM
    Thursday, June 18, 2009 1:26 AM

All replies

  • Hi James,

    The best way to solve this problem is indeed by adjusting the XSLT of the Core Results web part.
    Mirjam --http://www.sharepointblogs.com/mirjam
    Thursday, April 23, 2009 7:39 AM

  • Any ideas on how to do it? My XSLT knowledge isnt up to it yet? I think i know the section to change, but i dont know how to do a 'if ="" or ="SU_REPORT"

    Thanks
    Thursday, April 23, 2009 8:16 AM
  • Thanks, this is great (and not just for this little problem as im learning loads from it)

    I'm nearly there, i have the logic done, i just cant find anywhere that the actual FileName is stored. Can it be added, or do i have to start stripping it from the end of the URL.
    Thursday, April 23, 2009 1:45 PM
  • I'd have to try it myself but I thought file name was stored as part of the information.
    John
    SharePoint911: SharePoint Consulting
    Blog: http://www.rossonmoss.com
    Twitter: JohnRossJr

    MOSS Explained: An Information Workers Deep Dive into Microsoft Office SharePoint Server 2007
    Thursday, April 23, 2009 2:04 PM
  • * Modify search core web parts
    * In the "Results Query Options" update the Selected Columns property by adding a new column: <Column Name="Filename"/>

    * Under Data View Properties (of search core web part toolpart) edit the XSL by clicking on "XSL Editor..." button:
        *  Do a find for "<xsl:variable name="id" select="id" />, it should be in the Result template
         * Under the id variable, add a new variable:  <xsl:variable name="filename" select="filename" />   (yes, filename should be lowercase)
         * A few lines down you should see <span class="srch-Title">, update that section to the xsl below:

    <span class="srch-Title">
       <a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
    <xsl:if test="$isdocument &#61; 1">
    <xsl:value-of select="filename"/>
    </xsl:if>
    <xsl:if test="$isdocument &#61; 0">
        <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>
    • Proposed as answer by ryandale56 Thursday, June 18, 2009 6:41 PM
    • Marked as answer by JWatts Saturday, June 20, 2009 6:06 PM
    Thursday, June 18, 2009 1:26 AM
  • Nice one, thank you. Its slightly tidier than the version i eventually came up with, so i'll use yours from now on and am happy to mark it as the answer
    Saturday, June 20, 2009 6:07 PM