Using SharePoint Search for my communities overview

Using SharePoint Search for my communities overview header image

With the new community template available in SharePoint 2013 users get the freedom to choose what communities they can join and follow. If a community is no longer active they can choose to leave a community again. When they join a community they will become a member and end up in the member list of a community. On the other hand if you join a community not only will you end up in the members list but it will also ‘follow the site’.

As you will join a community it will end up in your site stream that will result in a neat overview of sites you follow. However as communities will not be the only sites you follow it there might be an ‘overflow’ of sites you follow. In a recent project I got the request to build something that would only return all the communities that a user had joined.

Besides introducing a new community template a whole set of search improvements have been released with SharePoint 2013. With those new search capabilities you have the opportunity to write smart queries allowing you to to tune the results and the way they are displayed. As you will end up in a list as member once you have joined a community we can use that list to query against and retrieve all items with that content type. Then we can also pass the search query parameter User into our query. That way only list items that begin with the desired content type and the display name of the user are returned:

ContentTypeId:0x010027FC2137D8DE4B00A40E14346D070D5201* AND {User}

Running this query will result in an overview of all items that contains your name in sites that you are joined. Below you can see that with this query the current user is joined in four communities.


All we then have to do is to write a Display Template that ‘translates’ Item URL into a Site Url, and instead of showing the Item Title shows the Site Title. To do so all we need is the SPSiteURL and SiteTitle properties, and push them into the layout you require: 

ctx['DisplayTemplateData']['ManagedPropertyMapping'] = { 'Link URL': ['SPSiteURL'], 'Title': ['SiteTitle'] };

var linkURL = $getItemValue(ctx, "Link URL");

var title = $getItemValue(ctx, "Title");


var titleLinkId = encodedId + title;

, '<a href="', linkURL, '" title="', $htmlEncode(title.defaultValueRenderer(title)), '" id="', titleLinkId, '">'
, title
, '</a>'

To do so you can just take a copy of the two line display template that is available and insert / overwrite parts of the logic to show the desired information in a view that suites your clients.

Loading comments…