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 I speak 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, I urge you to go read the following article (in french for now): SharePoint 2013 : Search – Presentation of Query Rules,

Scenario chosen for this article

I choose for this article the "Function" field:

  • "Job Title" Attribute in Active Directory,
  • "SPS-JobTitle" Internal name in SharePoint.

I will display a different "Promoted Result" depending on whether the function of the person is a "Tyrannical manager" or "Employee".

The steps

The 3 steps to implement this system are the following:

  • Create a Term for each "User Segment",
  • Develop a webpart 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

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 I will base myself for this article.

2. Via the 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

  • Implement the "Onload" method

  • 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

  • Compile, build, and deploy your wsp

  • 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)

Step 3 : Create the Query Rule(s)

1. Create a Query Rule and click on "Add User Segment" in the boxed section below

2. Enter a title and click on "Add user segment term"

3. Select your Term and click on "Save" in the 2 windows

4. In the "Query Conditions" section, click on "Remove Condition"

This will do the rule fire on all queries

5. Add your Promoted Result (or whatever) and click on "Save".

Here, a "Tyrannical manager" will see a sweet image (Bahamas), while a "Employee" will see the logo of the French agency managing unemployed people, with a encouragement message : “Finish your work, or you will go the agency !” ...:)


1. I launch my page as an "Administrator" (the manager), and I see the picture configured in the Query Rule

2. Then I log in as myself (the employee !), and I see my "custom" picture ...

Anonymous access

I 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.


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 my blog, but I will translate and transfer them on the TechNet Wiki.