SharePoint 2013 Content Search Web Part and filtering on User Profile Properties

I am working on a new SharePoint 2013 implementation for an organisation that has a particular desire to have as much personalised content as possible on the Intranet home page. The idea is to have say one main area on the home page for company news, then to have other areas that surface news targeted for Your Department and Your Job Title.

In order to achieve this we need a publishing site, Content Types that have Site Columns of the type Managed Metadata that are mapped to the People->Department and People->Job Title term sets. Then, we simply add some Content Search Web Parts to the publishing site home page and configure the KQL to return only pages that have matches for the appropriate User Profile property.
Note: I’m going to assume that you’ve got the farm setup with a functioning Managed Metadata service, Search service (with continuous crawling configured), and a User Profile service that is populated with several users all of which have values in their Department and Job Title properties.

The corresponding Managed Metadata People-Department and People-Job Title term sets should also have the values populated from the User Profile service.

In my examples below I am using Departments such as Finance and Product Development, and Job Titles such as Finance Manager, Accountant, Senior Project Manager, Project Manager and Developer. If you don’t have the exact same values in your user profiles then make sure you substitute the values in step 14 below with values form your profiles.

1. In Central Admin, create a site collection based on the Publishing Portal site definition.

2. Once the site collection is created, browse to the site.

3. Give Everyone permission to at least read the site.

4. Go to Site Actions->Site Settings->Site columns and create the following Site Columns:

Name: FilterOnDepartment
Type: Managed Metadata
Term Set: People->Department

Name: FilterOnJobTitle
Type: Managed Metadata
Term Set: People->Job Title

5. Go to Site Actions->Site Settings->Site content types and create a Content Type using the following settings:

Name: FilterOnUserProfile
Parent Content Type: Article Page (from the Page Layouts Content Type parent)

6. Add the following existing site columns to the FilterOnUserProfile content type:

FilterOnDepartment
FilterOnJobTitle

7. Go to Site Actions->Site Settings->Site libraries and lists
8. Click on Customise “Pages”
9. Click on Add from existing site content types
10. Add the following content type:

FilterOnUserProfile

11. Select Site Actions->Site Contents
12. Click on Pages
13. From the Ribbon, select the FILES tab
14. You will now add a series of pages by clicking on the New Document drop-down and selecting FilterOnUserProfile for each of the following values (once you create the page, you’ll be returned to the Pages library, for the page you just created select Edit Properies):

Title: Page For Department Finance
Page Layout: (Article Page) Body Only
(once page is created and you’ve clicked on Edit Properties)
Content Type: FilterOnUserProfile
Comments: This page has a FilterOnDepartment column value of Finance.
FilterOnDepartment: Finance

Title: Page For Department Product Development
Page Layout: (Article Page) Body Only
(once page is created and you’ve clicked on Edit Properties)
Content Type: FilterOnUserProfile
Comments: This page has a FilterOnDepartment column value of Product Development.
FilterOnDepartment: Product Development

Title: Page For Job Title Developer
Page Layout: (Article Page) Body Only
(once page is created and you’ve clicked on Edit Properties)
Content Type: FilterOnUserProfile
Comments: This page has a FilterOnJobTitle column value of Developer.
FilterOnJobTitle: Developer

Title: Page For Job Title Finance Manager
Page Layout: (Article Page) Body Only
(once page is created and you’ve clicked on Edit Properties)
Content Type: FilterOnUserProfile
Comments: This page has a FilterOnJobTitle column value of Finance Manager.
FilterOnJobTitle: Finance Manager

Title: Page Finance and Accountant
Page Layout: (Article Page) Body Only
(once page is created and you’ve clicked on Edit Properties)
Content Type: FilterOnUserProfile
Comments: This page has a FilterOnJobDepartment column value of Finance AND a FilterOnJobTitle column value of Accountant.
FilterOnDepartment: Accountant
FilterOnJobTitle: Accountant

15. Once you’ve created all of the pages you need to check in and publish a major version of each page.

16. Now you’ll need to wait for search to crawl the newly added content. If you have continuous crawling then you’ll need to wait at the most 15 minutes. If you don’t have continuous crawling you’ll need to execute a full crawl.
Note: If you’re impatient and want to know if the continuous crawl has found your new pages, in Central Admin go to the Search Service application, click on Search Schema and then enter owstaxid into the Managed property filter and click the -> button. You should see your site columns.

17. Once you’re happy that the crawl has finished you now need to check that there is managed properties created and populated with the values, browse to the home page of your publishing site and enter the following search criteria into the Search this site box:

owstaxidFilterOnDepartment:Finance
(for the site columns you created in step 4 a new managed property with the name owstaxid will have been created and populated by the crawl)

18. If you are seeing results from the previous search then you can proceed with the next steps of adding the web parts to the home page of the publishing site, if you’re not seeing results from the search then spend some time examining your search configuration and maybe do a full crawl.

19. Browse to the home page of the publishing site
20. Choose Site Actions->Edit Page
21. In the Page Content area edit to your taste (I add the text “This page will allow you to see articles based on your User Profile values for Department and Job Title.”
22. Delete all the existing web parts from the Top Left and Top Right zones.
23. In the Top Left zone click Add a Web Part and add a Content Search web part (from the Content Rollup category).
24. For the Content Search web part you just added select the Edit Web Part menu option.
25. In the Web Part editor on the right, click the Change Query button.
26. You will now be in the Build Your Query dialogue with the BASICS tab selected. Click the Switch to Advanced Mode option.
27. In the Query text box clear all the content and add the following:
owstaxidFilterOnDepartment:{User.Department}
Note: In a production environment you’d want to add several other search criteria here such as the content type but for the purposes of this small demo this query text will suffice.

28. Click the OK button
Note:If you’re carrying out all of these steps as say the setup account (like me) then you might be tempted to click the Test Query button in the previous step. If you do you’ll probably not see any results being returned unless the setup account has a Department value set in it’s User Profile.

29. In the Web Part editor on the right, in the Display Templates section choose the Two lines option from the Item drop down.
30. Expand the Property Mappings section, select the Change the mapping of managed properties… check box and then select the CommentsOWSMTXT option from the Line 2 drop down.
31. Expand the Appearance section and enter Department News for the Title and then select the Title Only option from the Chrome Type drop-down.
32. Click the OK button.
33. Save, check-in and publish the page.
34. Now log in as a user from the Finance department and check to see if you see two articles in the Department News web part.
35. You can now add another web part to the Top Right zone, this time you’re going to set the filter for Job Title. The key differences from the previous steps are for the Query Text use the following:
owstaxidFilterOnJobTitle:{User.SPS-JobTitle}
36. Finally, add a another web part to the Header zone, this web part will display news for Department OR Job Title (just to demonstrate that you can combine results). The Query Text to use is:
(owstaxidFilterOnDepartment:{User.Department} OR owstaxidFilterOnJobTitle:{User.SPS-JobTitle})
Note: The default operator is AND and so you *could* change this query to reduce the articles presented by removing the OR.

YMMV

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

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