Out of the box, SharePoint 2010 search displays all files that your search keyword hit. Just recently one of the readers was interested in how to limit the display of results of certain files types only.
There are few approaches on how to achieve that. One of the by creating a special scope for search and setting an exclusion rule to exclude all files that have a certain extension.
Another way to approach it is to modify search results XSL and perform checking of a metadata there; if the metadata matches the result you don’t want to show – you can hide it right there and then. As you see from below – our search results include DOC and ASPX files. Suppose you don’t want to show ASPX pages in search results.
To achieve that, you would do the following:
1. Perform a search to navigate to the search result page.
2. Enter the edit mode of the page.
3. Locate Search Core Results web part and enter the web part edit mode.
4. Under Core Results -> Display Properties click on XSL Editor to launch editing mode of the XSL that renders the results.
5. The easiest here is to copy the code into notepad or Visual Studio. Locate the following few lines of code:
<xsl:template match=”Result”>
<xsl:variable name=”id” select=”id”/>
<xsl:variable name=”currentId” select=”concat($IdPrefix,$id)”/>
<xsl:variable name=”url” select=”url”/>
This section is responsible for rendering each result. We’ll place a conditional statement here that will skip the rendering for each result that has an aspx extension in the URL. Add the following line of code right after the code from above:
<xsl:if test=”not(contains($url, ‘aspx’))”>
Finally, we have to close out conditional operator right at the end of the result rendering template. Locate the piece of code below in your existing XSL (the part in bold is where we close our condition).
</xsl:call-template>
<xsl:call-template name=”ViewInBrowser”>
<xsl:with-param name=”browserlink” select=”serverredirectedurl” />
<xsl:with-param name=”currentId” select=”$currentId” />
</xsl:call-template>
</span>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
That’s it. Now, just replace existing XSL in your web part properties with the one edited here and save the properties of the web part along with the page. Next time you perform your search, you will only see pages that are not of aspx extension.
Good Luck!

