Using search web parts to display relevant content to users

Since the SharePoint 2007 days we’ve been able to utilise audience targeting to display different content to different groups of users, whilst this works well its often not as granular as clients would like. Fortunately SharePoint 2013’s search now makes life easy, here’s how:

To start simple, lets say we need a web part that displays any policy and procedure documents related to the current user’s department. We can do this without a single line of code by using the content search web part (CSWP). Prior to building the search query we’re going to need to know three items:

  1. How to identify policy and procedure documents – In this case they have a content type named “Policies and Procedures”
  2. How to identify the departments that document has been tagged with – The search schema shows a managed property named owstaxIdDBDepartment that contains this information (Search the search schema for the name of your site column to find yours)
  3. How to identify which department the current user belongs to – Within the edit screen of the department user profile property, the name shows as SPS-Department

Using this information we can then build an appropriate search query:

ContentType=”Policies and Procedures” owstaxIdDBDepartment:{User.SPS-Department}

Troubleshooting tip – Setup a simple query to return all policy and procedure documents, set the display template to diagnostic, then use the property mapping setting to display the managed property your using to query against the documents department to confirm exactly what is being returned.

Lets say we want to get a bit more fancy and create a web part that displays news articles that are relevant to the current users skill set. To ensure users don’t miss news posts, we want the web part to return news posts that contain the users skill within any of their managed metadata tags.

The owstaxidmetadataalltagsinfo managed property makes life very easy, it contains the data from all managed metadata fields. So knowing that all news articles have the content type name of “News Articles” and the user profile property that contains the users skills is named SPS-Skills, the query would be as follows:

ContentType=”News Articles” owstaxidmetadataalltagsinfo:{User.SPS-Skills}

For more info on SharePoint’s Keyword Query Language see – https://msdn.microsoft.com/en-us/library/office/ee558911.aspx

rollup2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s