By: Neil Barkhina
One of SharePoint’s best features in my opinion, and one that is often underutilized, is Enterprise Search. Everyone knows you can do searches in SharePoint, but in order to unlock it’sreal potential, certain concepts must be understood. These include things like scopes and managed properties. Over the years I have also learned some tricks which have helped better use these features.
Use the correct version
Just to be clear, there are two types of searches that can be performed in SharePoint. One is the “free” version which is called Windows SharePoint Services Search, and the other one is Enterprise Search which is what you get with Office SharePoint Server. The surprising thing is, many customers we have come across over the years own MOSS, but still run WSS Search! The easiest way to know the version you’re using is to look at the search results page. If the URL ends in “/_layouts/osssearchresults.aspx”you are running the freebee:

However, if your search results page comes back in a URL with /SearchCenter then you are using Enterprise Search:

XSLT Transformations
Enterprise Search uses a special site called the Search Center. A big advantage is that the search results page uses XSL to format its results. This means that you can fully customize it as far as look and feel, and also add functionality. One example is an addition we made to our own intranet. You know how sometimes you want to view the document library that a document is in, but not necessarily want to click the document itself?

Well normally you’d be straining with you mouse to highlight just the base part of the URL in the browser. What we did was modify the XSL to include a “Navigate to Parent” under each search result. To edit the XSL, edit the search results page and modify the Search Core Results web part. The XSL Editor Button is one of the web part properties:

Then it’s basically a matter of adding a function called “mcs-get-parent” to display the link. Here is XSL:
<xsl:templatename="mcs-get-parent">
<!-- getting the url to the item, returned from search -->
<xsl:paramname="result-url"/>
<xsl:variablename="res1">
<xsl:choose>
<!--for now i have now idea how to deal with urls with ? chars, so we would skip them -->
<xsl:whentest="contains( $result-url, '?' )">
<xsl:value-ofselect="$result-url"/>
</xsl:when>
<!--for urls that are not referring the root of the web applications, we perform the processing -->
<xsl:whentest="contains( substring-after( $result-url,'https://') ,'/')">
<xsl:call-templatename="mcs-strip-filename">
<xsl:with-paramname="x"select="$result-url"/>
</xsl:call-template>
</xsl:when>
<!-- for all other conditions we do nothing -->
<xsl:otherwise>
<xsl:value-ofselect="$result-url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- postprocessing-->
<xsl:variablename="res2">
<xsl:choose>
<!-- if search returned is the item like http://test we would leave it untouched -->
<xsl:whentest="$result-url=$res1">
<xsl:value-ofselect="$res1"/>
</xsl:when>
<!-- if search returned us the result like http://test/sites/site, than the parent should be http://test and not http://test/sites -->
<xsl:whentest="substring-after($result-url,'sites/')=$res1">
<xsl:value-ofselect="substring-before($result-url,concat('/sites/',$res1))"/>
</xsl:when>
<!-- in all other situations we just strip the doc name from the end and return the result -->
<xsl:otherwise>
<xsl:value-ofselect="substring-before($result-url,$res1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<spanclass="srch-URL"><xsl:textdisable-output-escaping="yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text><ahref="{$res2}">NAVIGATE TO PARENT</a></span>
</xsl:template>
<xsl:templatename="mcs-strip-filename">
<xsl:paramname="x"/>
<xsl:choose>
<xsl:whentest="contains($x,'/')">
<xsl:call-templatename="mcs-strip-filename">
<xsl:with-paramname="x"select="substring-after($x,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-ofselect="$x"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Since our SharePoint intranet uses SSL the XSL was modified to only display HTTPS:// results, however this can be easily changed if your site uses normal http. To display the Navigate to Parent link simply call the XSL Template by passing in the url field that comes back from the search results:
<xsl:call-templatename="mcs-get-parent">
<xsl:with-paramname="result-url"select="url" />
</xsl:call-template>
Search Queries
When performing a search, there is specific syntax you can use to narrow down your results. SharePoint uses a special construct called Managed Properties to allow you to filter search results. The difference between Managed Properties and Crawled Properties is that Managed ones get exposed to the end user for searching. How a Managed Property gets created is abstracted from the user, the actual interface resides in the Shared Services Provider Web Site. But a managed property can be made up of many crawled properties such as SharePoint Columns and even Office Metadata. Users of Office 2003 and earlier have probably encountered this. Documents contain metadata that sits behind the content such as the Author of a document, date created and other metadata as well. To search on a managed property you simply use the syntax [property]:“value”. Here are some examples that you can type right into the SharePoint search box!
1. Fileextention:xlsx - this will do a search for all Excel 2007 documents
2. ContentType:"Discussion"- this will return results from discussion boards.
3. Author:“NeilBarkhina” - return documents that I have authored
The examples above are built-in managed properties that you get out of the box. However you can create your own managed properties as well such as “Client” and “Company” tuned to your specific business needs. In future posts I will go into more details of the Enterprise Search Architecture and platform.
-Neil Barkhina