SharePoint Social Features: Practical Discoveries, Part 1
SharePoint Social Features: Practical Discoveries, Part 1
As SharePoint 2010 introduced support for social networking, we started getting numerous requests to employ such features in our designs. In doing so we've discovered several interesting applications of this functionality. The following set of posts is dedicated to our research in this area, and assumes reader's basic familiarity with SharePoint 2010 social features.
Both server and client APIs expose a great deal of functionality that allows for browsing through the social elements, which consist of Notes, Ratings and Tags. However, even these great APIs can quickly run out of options for relatively common tasks. To name a few examples:
- Get the most tagged item within the specified period of time. Example: a web part to show the most popular item of the week;
- Get all users who tagged specific item. Example: a web part to show item's popularity by Department/Office/Location/Team/anything else in user profile;
- Get all users who used specific tag. Example: a web part to show tag's popularity by any user profile property;
- Get the most used tag within the specified period of time. Example: a web part to show "Tag of the month";
By looking at the great "Manage Social Tags and Notes" page within the User Profile Service Application one would assume the mentioned examples would be relatively straightforward to implement, as all of those cases are covered by the search UI:
Well, let's take a look at the API. Microsoft.Office.Server.SocialData.SocialTagManager provides access to the social tags we're interested in. Basically, we're down to GetAllTerms(), GetAllUrls(), GetTags(), GetTerms(), and GetUrls() in terms of discoverability. Neither of them accepts time constraints, which rules out two of our four examples. Neither SocialUrl nor SocialTag objects, returned by these methods give any information about the users who applied tags. Strictly speaking, the SocialTag class does have an Owner property that contains the UserProfile object. However all SocialTagManager methods returning SocialTag objects do so for the current or a specified user only, rendering the Owner property relatively useless. This eliminates remaining two examples as well.
How does SharePoint do it? There are about 25 internal overloads for the mentioned 5 public methods. For example, the following method allows the owner object to be nullable, thus returning SocialTag objects for any user while filtering by the dates of application:
internal SocialTag[] GetTags(Uri url, UserProfile owner, DateTime? fromDate, DateTime? toDate)
What are the options for dealing with this situation?
- Use available API and get the desired results through multiple method invocation and filtering. For instance, invoke GetTags() for every available user profile, and apply date or URL filtering to the resulting arrays. This will be an extremely time-consuming operation, so even a nightly timer job might not be a good solution for a farm with dozens of thousands of user profiles;
- Access the User Profile Service Application SocialDB directly by either calling the stored procedures like dbo.proc_SocialTags_GetForUrlByTime(), or by executing queries against the SocialTags and Urls tables which have a pretty straightforward schema. Of course, this would put you into quite a jeopardy in terms of support and future updates;
- Do a smart assessment of the customer's business needs, trying to either avoid or minimize the impact of such implementation. For example, if there's a need for a "most popular item of the week", try to scope it down to a feasible number of users, like department site members.
We will continue our Social Features research in the next post.










