SharePoint 2013: Search - User Segmentation
Introduction
The concept of "User Segmentation" is a new feature in SharePoint 2013 that allows you to view search results based on user attributes, named "User Segments".
When speaking of attributes, these are not only attributes coming from the user's profile, they can be of any type (as the type of browser used), as you must code what you choose to be the criterion, so you have a wide field of action.
The principle is that a WebPart (you have developed) will attempt to match the value of the chosen attribute with the value of a Term specified as the "User Segment" of a Query Rule.
If the term is found, its ID is passed to the query and the action of the Query Rule is executed.
Note: If you did not understand the previous two sentences, we urge you to go read the following article (in French for now): SharePoint 2013: Search – Presentation of Query Rules,
Scenario chosen for this article
We chose for this article the "Function" field:
- "Job Title" Attribute in Active Directory,
- "SPS-JobTitle" Internal name in SharePoint.
It will display a different "Promoted Result" depending on whether the function of the person is a "Tyrannical manager" or "Employee".
The steps
The three steps to implement this system are the following:
- Create a Term for each "User Segment",
- Develop a web part inheriting the ContentBySearchWebPart and which will take into account these Terms,
- Create (or more) query rule (s) to treat different "User Segment".
Step 1: Create the terms related to the "User Segments"
Create via the interface or code the Terms representing the values of the property on which you want to start, here "Tyrannical manager" and "Employee".
You can create these Terms in several ways:
1. By matching user properties
The good news, in this case, SharePoint 2013 uses a default Term Set named "People" to store the Department, Job Title and Location property values, issued from the User Profiles.
And it is precisely on this Term Set "Job Title" that we will base this article on.
http://spasipe.files.wordpress.com/2013/07/33.png
2. Via your site collection ("Site Settings")
3. Via code
NavigationTerm term = navigationTermSet.CreateTerm("Tyrannical manager", NavigationLinkType.FriendlyUrl, Guid.NewGuid());
Step 2: Create the WebPart
Note: If you cannot develop (or do not want to, it also works in this case), some articles located at the end of this article (in the "References" chapter) provide ready to use Visual Studio source code.
To develop this webpart, you will have to:
- Make it inherit ContentBySearchWebPart
http://spasipe.files.wordpress.com/2013/07/74.png
- Implement the "Onload" method
http://spasipe.files.wordpress.com/2013/07/82.png
- Create the method that will attempt to match your property with one of the Terms, by specifying the property to be used and the name of the Term Set
http://spasipe.files.wordpress.com/2013/07/44.png
- Compile, build, and deploy your wsp
http://spasipe.files.wordpress.com/2013/07/66.png
- Insert the webpart, and insert a second webpart. Your custom webpart or a "Content Search" that you configure as follows (it retrieves the results of your custom webpart)
http://spasipe.files.wordpress.com/2013/07/122.png?w=595
Step 3: Create the Query Rule(s)
1. Create a Query Rule and click on "Add User Segment" in the boxed section below
http://spasipe.files.wordpress.com/2013/07/75.png?w=595
2. Enter a title and click on "Add user segment term"
http://spasipe.files.wordpress.com/2013/07/77.png
3. Select your Term and click on "Save" in the two windows
http://spasipe.files.wordpress.com/2013/07/83.png
4. In the "Query Conditions" section, click on "Remove Condition"
http://spasipe.files.wordpress.com/2013/07/64.png
This will do the rule fire on all queries
http://spasipe.files.wordpress.com/2013/07/73.png
5. Add your Promoted Result (or whatever) and click on "Save".
http://spasipe.files.wordpress.com/2013/07/92.png
Here, a "Tyrannical manager" will see a sweet image (Bahamas), while an "Employee" will see the logo of the French agency managing unemployed people, with an encouraging message: “Finish your work, or you will go the agency !” ...
Result
1. Launch the page as an "Administrator" (the manager) to see the picture configured in the Query Rule
http://spasipe.files.wordpress.com/2013/07/103.png
2. Then log in as the employee and see the "custom" picture ...
http://spasipe.files.wordpress.com/2013/07/114.png
Anonymous access
We recommend you to read this article from Waldek Mastykarz, focused on problems using the trio "Content Search Web / User Segments / Anonymous Search Results Cache".
In summary: It seems that at this moment it is not possible to use Anonymous Cache Search Results with User Segments.
References
- User segmentation in SharePoint 2013,
- Using User Context (AKA Segmentation) in Search with SharePoint 2013
- Set up User Segmentation to drive adaptive experiences in a Product Catalog in SharePoint 2013
- Using the Anonymous search results cache on SharePoint 2013 public-facing websites
- Adaptive experiences in a Product Catalog in SharePoint 2013 using Facebook location data
- User Context Sensitive Searching In SharePoint 2013 Part 1
- User Context Sensitive Searching In SharePoint 2013 Part 2
See Also
This article is part of a series of articles dedicated to the SharePoint 2013 search.
They are actually written in French and hosted on the author's blog, but we will translate and transfer them on the TechNet Wiki.