Friday, December 30, 2011

SharePoint 2010 Search Scope to Aggregate Content

For scalability in SharePoint, I’m in favor of provisioning site collections instead of sub sites.  However, the challenge with Site Collections is that they are isolated from each other so you need to create custom solutions to aggregate content from across site collections.  Using SharePoint Search Scopes and the Search Core Results web part provides a way where an administrator could create an aggregated solution.  I also like to use search query web parts because it takes SQL out of the query loop and by modifying the web part’s XSL you have options for formatting the way results display (SharePoint Designer helps).

I had a requirement where a client wanted to display a feed of recent updates across site collections in a web part on a top level site.  I previously implemented a site provisioning solution for them which uses a site template – the template contains a discussion board, an images library, an announcement list, a document library, and a calendar.  The feed had to display similar to the My Sites Newsfeed where the feed item gives brief description of what type of content has been added or updated (e.g., A new image has been added…, A new discussion has been posted…, etc.).

The first thing I did was to create a Search Scope in the Search Service Application.  Within the search scope, I added the following rules:

Scope Rule Type Web Address Behavior Comment
Web Address

https://sites.xyz.com/sites

Include Rule to only include sites under the web address (we’re using a managed path under which all the sites are provisioned – in sample “sites” is the managed path)

The below rules use the property “contentclass”.  Contentclass is a search administration property commonly used in SharePoint search scopes.  More information on the ContentClass property can readily be found by doing a web search.

Scope Rule Type Property Query Behavior Comment
Property Query

contentclass=STS_ListItem_DiscussionBoard

Include This brings back all of the discussion board items
Property Query

contentclass=STS_ListItem_PictureLibrary

Include This brings back all of the Picture Library items
Property Query

contentclass=STS_ListItem_Events

Include This brings back all of the Calendar list items
Property Query

contentclass=STS_ListItem_Announcements

Include This brings back all of the Announcements list items
Property Query

contentclass=STS_ListItem_DocumentLibrary

Include This brings back all of the Document Library items
Property Query

contentclass=STS_List_850

Exclude The site template uses the Publishing Features which includes a “Pages” library – we don’t want results from the Pages library, just Documents, Announcements, Images, Events, and Discussion Board items

With this scope created, the next thing to do is to add a Search Core Results web part to a page on your top level site and set the Fixed Keyword Query value to use this scope.  With the fixed query, the results will display in the web part whenever the page loads.  Also set the Cross-Web Part query ID to something other than “User Query” (in the sample below, it is set to “Query 3”).

image

My client also wanted the results to display in Newsfeed format.  To do this, I needed to switch the Search Core Results Display properties to set sorting to Modified Date, deselect Use Location Visualization where I add contentclass as a column to bring back in search results (I need this to create conditions in my XSL to determine what to display in the feed statement) and also added the column for the managed property “SiteTitle” which I use to display the name of the site where the update occurred.

image

Finally, using SharePoint designer, I was able to take the raw XML search results and generate the XSLT to display the results in feed format which I added via the XSL editor in the Search Core Results Web Part (see MSDN guidance here for customizing search results and Tobias Zimmergren has the step-by-step for SP 2007 here which isn’t much different in SP 2010).

No comments:

Post a Comment