none
Customize Clickable Link In Search Results RRS feed

  • Pregunta

  • I'm using Search Server 2010 Express and I want to customize the clickable URL, as well as the displayed URL, for search results of files.  The search server is indexing a share used only by Mac users so when they click the link of the search results, instead of it going to "files://link" I'd like it go to "smb://link" and instead of displaying "files://link" it should similarly display "smb://link".  It looks like I need to edit the XSL of the Core Results webpart, but as I have never done this before I'm not sure specifically which objects I need to modify to get my intended results.  Any help is appreciated!

    viernes, 3 de mayo de 2013 20:45

Respuestas

  • In the section of XSL above, add the following variable (smburl), and use it to generate the link.This will update the link the Title is using.

    <xsl:choose>
      <xsl:when test="substring($url,1,5) = 'file:' and $IsDesignMode = 'False'">
    	<xsl:variable name="smburl" select="concat('smb:',substring($url,6,string-length($url)))"/>		
    	<xsl:text     disable-output-escaping="yes">&lt;a href="</xsl:text>
    	<xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode($smburl)" />



    To update the URL output (at the bottom), edit the section that starts with a P class="srch-Metadata1" section, adding an additional xsl:when case.

    <p class="srch-M

    etadata1"> <span><span class="srch-URL2" id="{concat($currentId,'_Url')}"> <xsl:choose> <xsl:when test="substring($url,1,5) = 'file:' and $IsDesignMode = 'False'"> <xsl:variable name="smburl" select="concat('smb:',substring($url,6,string-length($url)))"/> <xsl:value-of select="$smburl"/> </xsl:when> <xsl:when test="hithighlightedproperties/HHUrl[. != '']"> <xsl:call-template name="HitHighlighting"> <xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="url"/> </xsl:otherwise> </xsl:choose> </span>

    It looks like this:



    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.



    • Editado Matthew Yarlett martes, 7 de mayo de 2013 10:05 Added a picture.
    • Marcado como respuesta irlrobot martes, 7 de mayo de 2013 13:57
    martes, 7 de mayo de 2013 10:02

Todas las respuestas

  • Hi irlobot,

    After you search, in search results page, click edit page, find  the Search Core Results Web Part, click edit Web Part. This opens the Search Core Results Web Part tool pane. Then go to display properties section, uncheck use location visualization, then click edit xsl editor.

    For more information about change Search core result link:

    http://spointthoughts.blogspot.com/2012/08/how-to-change-sharepoint-2010-search.html

    Note: To achieve this you must edit the XSLT of Search Core Result web part. You can't edit the default search page "_layouts/OSSSearchResult.aspx". Hence you should create a custom search center site.

    After you have created a custom search site, modify the site collection to use the custom search center site.(go site settings->search settings)

    Best Regards.


    Kelly Chen
    TechNet Community Support

    lunes, 6 de mayo de 2013 6:07
    Moderador
  • Thanks for your suggestion.  I was hoping for a little more of a hand holding answer, but it sounds like this might be more complex than I was hoping.  I'm not really sure what I need to edit in the XSLT to achieve my results.


    lunes, 6 de mayo de 2013 16:50
  • It's not a quick and easy one to work with sadly.

    This might be of use: if memory serves it allows you to see the raw XML feed that search returns.

    http://sridharu.blogspot.co.uk/2008/01/how-to-read-raw-xml-from-sharepoint.html#!/2008/01/how-to-read-raw-xml-from-sharepoint.html

    lunes, 6 de mayo de 2013 21:18
  • Thanks.  I've been trying to modify the $url variable to replace file: with smb:, but I'm not having much luck.

    I have literally zero experience with XSL, but I'm assuming this is where the magic happens:

    <xsl:choose>
          <xsl:when test="substring($url,1,5) = 'file:' and $IsDesignMode = 'False'">
            <xsl:text     disable-output-escaping="yes">&lt;a href="</xsl:text>
            <xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode($url)" />
            <xsl:text     disable-output-escaping="yes">" id="</xsl:text>
            <xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode(concat($currentId,'_Title'))" />
            <xsl:text     disable-output-escaping="yes">" title="</xsl:text>
            <xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode(title)" />
            <xsl:text     disable-output-escaping="yes">"&gt;</xsl:text>
            <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="srwrt:HtmlEncode(title)"/></xsl:otherwise> 
            </xsl:choose>
            <xsl:text disable-output-escaping="yes">&lt;/a&gt;</xsl:text>
          </xsl:when>
          <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>
        </xsl:choose>

    I tried creating a $url2 variable and setting it to "replace($url,'file:','smb:')" and modifying the above accordingly but that didn't seem to work.

    At this point I'd even be happy with just simply adding an additional line to each result with my desired format (e.g. "smb://file/location/name.whatever") and keeping the original results as well.

    lunes, 6 de mayo de 2013 21:48
  • In the section of XSL above, add the following variable (smburl), and use it to generate the link.This will update the link the Title is using.

    <xsl:choose>
      <xsl:when test="substring($url,1,5) = 'file:' and $IsDesignMode = 'False'">
    	<xsl:variable name="smburl" select="concat('smb:',substring($url,6,string-length($url)))"/>		
    	<xsl:text     disable-output-escaping="yes">&lt;a href="</xsl:text>
    	<xsl:value-of disable-output-escaping="yes" select="srwrt:HtmlAttributeEncode($smburl)" />



    To update the URL output (at the bottom), edit the section that starts with a P class="srch-Metadata1" section, adding an additional xsl:when case.

    <p class="srch-M

    etadata1"> <span><span class="srch-URL2" id="{concat($currentId,'_Url')}"> <xsl:choose> <xsl:when test="substring($url,1,5) = 'file:' and $IsDesignMode = 'False'"> <xsl:variable name="smburl" select="concat('smb:',substring($url,6,string-length($url)))"/> <xsl:value-of select="$smburl"/> </xsl:when> <xsl:when test="hithighlightedproperties/HHUrl[. != '']"> <xsl:call-template name="HitHighlighting"> <xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="url"/> </xsl:otherwise> </xsl:choose> </span>

    It looks like this:



    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.



    • Editado Matthew Yarlett martes, 7 de mayo de 2013 10:05 Added a picture.
    • Marcado como respuesta irlrobot martes, 7 de mayo de 2013 13:57
    martes, 7 de mayo de 2013 10:02
  • Matthew thank you so much, you are the man!
    martes, 7 de mayo de 2013 13:58