User Context Properties
In SharePoint, you can create and edit user contexts through the UI. Under Site Settings –> FAST Search User Context, you will find all of your user contexts. The page to create a User Context looks like this out of the box:
Useful page, but not really right? If you want some more depth, you will have to do some digging into User Profiles. Go to Central Administration –> Service Applications –> <Your User Profile Service Application> –> Manage User Properties. Here you will find a list of user properties that are used in SharePoint, and these will be the key to making User Contexts and Site Promotions valuable and create a rich user experience for searches.
So first, let’s add a new property to the User Context. Let’s say that the User’s “Department” is an important factor in search relevancy. Therefore we want items relevant to the User’s Department to show up first in search results. To do this, we need to execute a couple PowerShell scripts.
View Current User Context Properties
First, let’s see what User Context properties are already available. If we haven’t touched them before, then we should see two of them, “SPS-Location,SPS-Responsibility”. We will be using the SharePoint PowerShell.
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
Where “FASTQuery” is the <Name of your FAST Query SSA>.
Add User Context Property
We need to make sure that we use the Name of the User Profile Property rather than the Display Name. This is especially important if we are using custom user profile properties. Also, we will need to include the old user context properties in this script, otherwise, they will be overwritten.
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
Troubleshooting: Now if you go to your UI, often you won’t see any changes (the changes will be reflected in PowerShell however)! The fastest way that I’ve seen to get these changes to show is an IIS Reset. If there is a way around this, please let us know. Therefore, type in iisreset into your PowerShell, then check the UI after it has completed. It should now look like this:
Add User Contexts Using PowerShell
Now that we have some new properties to play around with, let’s add some User Contexts! In the FAST PowerShell, run the command Get-FASTSearchSearchSettingGroup. This will return the FAST Search Setting Group(s) that are on the machine. There should only be one straight out of the box. We will need the Name for the next step.
2: $context = $searchSettingGroup.Contexts.AddContext(“USA Marketing”) 3: $andExpression = $context.AddAndExpression() 4: $orExpression = $andExpression.AddOrExpression() 5: $orExpression.AddMatchExpression(‘SPS-Location’,‘USA’) 6: $orExpression.AddMatchExpression(‘Department’,‘Marketing’) 7: 8: # Optional not Expression (remove #) 9: # $not = andExpression.AddNotExpression() 10: # $not.AddMatchExpression(‘SPS-Location’,‘Japan’) 11: # $not.AddMatchExpression(‘SPS-Location’,‘Canada’)
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
This next script will add a new User Context. The true usefulness of doing this in PowerShell is the added ability to use the “not” expression to truly filter your User Context. Besides that, why is this even useful over the UI? Mainly because it’s easily portable, and you can quickly execute your PowerShell script when it’s time to move from development to production. This is handy, especially if you have multiple User Contexts, but even more so when we begin adding Site Promotions.
Add Site Promotions Using PowerShell
Handling site promotions and demotions can be a real hassle, especially when we begin dealing with an environment with many sites and sub-sites. Having PowerShell will make this process quick and portable from a development environment to a production environment.
Here, we begin talking about the use of “boosting” relevance and using Site Promotions. Here, we will be working with a promotion without using Keywords. This could be considered something closer to “scoping”, however the search will still extend beyond the scope of the sites included in the search. PowerShell allows you to choose your boost value automatically, assign multiple websites to your boost, and select the User Context(s) to include.
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode, .ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode pre
{margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .rem
{color:#008000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .str
{color:#006080;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .op
{color:#0000c0;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .preproc
{color:#cc6633;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .html
{color:#800000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .attr
{color:#ff0000;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass35C7684F8D3F46ACAC92B08CAAE6D498 .csharpcode .lnum
{color:#606060;}
PowerShell is a clean method of adding Site Promotions to specific User Contexts in FAST Search. If you check under Site Settings –> FAST Search site promotion and demotion, you should see your new site promotion with its User Context(s) attached.
References: http://technet.microsoft.com/en-us/library/ff191225.aspx, http://blogs.technet.com/b/speschka/archive/2009/12/09/using-custom-properties-to-create-a-fast-search-for-sharepoint-2010-user-context.aspx