Using User Context (AKA Segmentation) in Search with SharePoint 2013


Using a context to represent the current user in search was something that we first introduced in FAST Search for SharePoint 2010.  If you're interested in how it worked back then you can take a look at this post:  http://blogs.technet.com/b/speschka/archive/2009/12/09/using-custom-properties-to-create-a-fast-search-for-sharepoint-2010-user-context.aspx.  In SharePoint 2013, we don't have the same exact feature, but we have to replace it is called User Segmentation.  Now rather than me trying to explain User Segments, what they are, and how they work, someone on the search team has already done a bang up job of that here: http://blogs.msdn.com/b/adaptive_experiences_in_sharepoint_2013/archive/2012/11/14/set-up-user-segmentation-to-drive-adaptive-experiences-in-a-product-catalog-in-sharepoint-2013.aspx.  I really encourage you to go read this blog entry, he does a great job of explaining what it is and an example of how to use it.

I'm not here to steal his thunder or take credit for it, but here's what I have done.  When you read that post you'll see that it mentions having to write a custom web part to figure out any user segmentations that should be applied to the current query and then it adds them to it.  In the blog it describes adding a user segmentation based on a property of the browser.  What I decided to do is to write a web part that adds a user segmentation based on the current user's department.  For those of you who have not heard, when you do a profile import from Active Directory in SharePoint 2013, we automatically import all of the unique Department values into a special term store.  This makes it a great choice to do some customization based on the current user's department.

One question that may come up is "if I am going to present content based on a user's department, why not just use audiences?"  That's a fair question, and here's the difference.  With audience targeting, it's a simple on / off switch – you either show a web part or not.  With user segmentation I can take that info out of the profile or anywhere else, and I can customize the content that's shown.  Since I'm using a query rule, I can execute one or more additional queries for a user, I can add a promoted result, or I can even change the ranking of a query – for example if I want to target certain content to be shown higher in the search results based on the department you work in.  These are just some fantastically cool features that you get with search in SharePoint 2013.

So, to help you along in using this feature, I'm just attaching my entire Visual Studio project – the compiled web part assembly, solution, and source code – for the web part that adds the current user's department to the user segmentation.  After that you can do with it what you will – use it as is, or use it as the basis to refine or write your own web part for managing user segmentation.  There are a couple of points I wanted to highlight about the use of user segmentation and this web part when you read the post I linked to above:

  • When you create the query rule, by default it's configured to query the catalog for the publishing site.  If you go with this option then you won't get any search results.  Instead, choose the option to query "All Sources".  The picture of the query rule configuration in the post shows this but does not call it out.  Since you need to change the default behavior for this to work, I am just calling it out.
  • In the post it talks about using a different web part to display the results of whatever content you are highlighting when using the user segmentation.  In this case (as the post alludes to), my web part inherits from the ContentBySearchWebPart, so you can use the control both to set the user segmentation as well as to display the highlighted content.  The only thing that's a little different from what's described in the post, is that when you add the web part to the page you will have one different value in the Settings property for the web part.  In the Settings, just set the "Query results provided by" property to "This web part".

That's it – you are ready to go now.  Hopefully you will all find some interesting scenarios for user segmentation in your searches.  For my particluar scenario when I was writing this I was targeting some special training for employees that belonged to an "Executive" department.  As a result when they hit the page where my web part is being used, they see this banner and link for special insider trading training that they will all have to take:

SearchUserContext.zip

Comments (3)

  1. alexandrad9x says:

    Tao http://dichvuketoanlongbien.com/
    Rủa
    http://dichvuketoanlongbien.com/a2-96-dich-vu-ke-toan-tron-goi.html
    Thằng http://dichvuketoanlongbien.com/a2-98-dich-vu-ke-toan-thue.html
    Cờ
    http://dichvuketoanlongbien.com/a2-103-dich-vu-bao-cao-tai-chinh.html
    http://dichvuketoanlongbien.com/a2-97-dich-vu-quyet-toan-thue.html
    Nào
    http://dichvuketoanlongbien.com/a2-114-dich-vu-ke-toan-tai-29-quan-huyen.html
    Soi
    http://dichvuketoanlongbien.com/i780-dich-vu-ke-toan-thue-tron-goi-tai-bac-ninh.html
    Tài
    http://dichvuketoanlongbien.com/i779-dich-vu-ke-toan-thue-tron-goi-tai-bac-giang.html
    Khoản
    http://dichvuketoanlongbien.com/i778-dich-vu-ke-toan-thue-tron-goi-tai-phu-tho.html

    http://dichvuketoanlongbien.com/i781-dich-vu-ke-toan-thue-tron-goi-tai-hung-yen.html
    Link
    http://dichvuketoanlongbien.com/i782-dich-vu-ke-toan-thue-tron-goi-tai-vinh-phuc.html
    Của
    http://dichvuketoanlongbien.com/i783-dich-vu-ke-toan-thue-tron-goi-tai-hai-phong.html
    Tao. http://www.trungtamketoan.com.vn/
    Chúng
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-ha-noi.html
    Mày
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-tp-hcm.html
    Đủ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-quang-ninh.html
    Trình
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-duong.html
    Thì
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-giang.html
    Tự
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-bac-ninh.html
    Đi
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hai-phong.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-nam-dinh.html
    Làm.
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thai-binh.html
    Việc
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-thanh-hoa.html

    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-vinh-phuc.html
    Phải
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-hung-yen.html
    Rẻ
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-phu-tho.html
    Rách
    http://www.trungtamketoan.com.vn/p/trung-tam-dao-tao-ke-toan-tai-binh-duong.html
    Như http://www.tosvn.com
    Thế. http://iketoan247.blogspot.com
    Loại http://tailieuveketoan.blogspot.com
    Chó http://mauhinhnendep.blogspot.com
    Má. http://www.tosvn.com/search/label/Hack%20CF
    Tao http://www.tosvn.com/search/label/Hack%20AvatarStar
    Rủa http://www.tosvn.com/search/label/Hack%20Warcraft-Dota2
    Những http://hocketoan360.com/category/tai-lieu-ke-toan/
    Thằng http://iketoan247.blogspot.com/search/label/thong-tin-kinh-te
    Soi http://iketoan247.blogspot.com/search/label/tin-bai-ve-thue
    Tao http://hoclamketoan.edu.vn/
    Sẽ http://hoclamketoan.edu.vn/category/khoa-hoc-ke-toan
    Tan http://hoclamketoan.edu.vn/category/dich-vu-ke-toan
    Cửa http://hoclamketoan.edu.vn/category/hoc-lam-ke-toan
    Nát http://hoclamketoan.edu.vn/category/tai-lieu-ke-toan
    Nhà http://hocketoan360.com/
    Haha http://hocketoan360.com/category/khoa-hoc-ke-toan/
    http://hocketoan360.com/category/dich-vu-ke-toan/

  2. Does it have to be "Custom" says:

    Is there any way to use User Segmentation without going Custom? Can I just promote a result based on User Profile Properties?

  3. m88 says:

    m88 :http://m88en.com/new-online-casino-deposit-bonus-codes-2015/
    M88.com offer online sports games Asia, Sports Betting Asia, Sports Betting Sites Asia.

    m88asia : http://m88en.net/m88-bet-mansion88-online-casino-online/
    Link to M88BET phone: m88en.com. – Register and Open Betting Account and Membership M88BET.

    m88bet :
    http://www.linkm88vip.com/2014/12/m88-asia-main-home-register-online-free.html
    MANSION88 the house is one of the largest and most prestigious. Appeared quite early in the Asian market, the so-MANSION88 currently attracts more players.

    link m88 :
    http://m88wiki.com/google-chrome-bookmarks-fastest-m88-link/
    Home the M88 is the official sponsor of the football club in the Premier League
    Wish you happy with the new M88
    m88 casino online : http://m88free.com/register-m88-football-betting/