Manually Adding Query Suggestions in SharePoint 2010

One of the great new features around Search in SharePoint 2010 is the concept of query suggestions.  There are pre-query and post-query suggestions.  A pre-query suggestion is a type-ahead feature that appears in the search box on the search page.  As you start typing in your query, SharePoint will go find other queries that have been executed with results and populate the type ahead drop down for you.  We only use queries that return results so we don’t suggest something that will bring back zero matches.  A post-query suggestion is similar, only it appears after you have executed a query.  It finds similar queries that have been executed and return results, and it displays them by default in the top right corner of the search results page.  Clicking on a post-query suggestion will execute that query for you.

One of the important things to remember about query suggestions though is that since they are built based on user’s performing searches and clicking through results, when you start out with your SharePoint farm you will not see any suggestions.  I’m going to show you how to seed the suggestions manually to get things going.  The suggestions you add in this manner show up as both pre-query and post-query suggestions.  Adding them manually is useful for getting this started or just seeing how the feature works; you may also have some set of query suggestions that you ALWAYS want to show up no matter what query is executed.  Also note that these steps were tested and work on the SharePoint escrow build (you TAP and RDP customers know which one this is) but I don’t think they work on the public beta bits.  This will be good info though for everyone once you have RTM bits. One final note – this process *should* work for both SharePoint Search and FAST Search for SharePoint. So here are the steps:

  1. Get a reference to your search service application.  If you type Get-SPEnterpriseSearchServiceApplication it will give you a list of them.  In this example I’m going to use the default name created with the SharePoint farm wizard:
    1. $ss = Get-SPEnterpriseSearchServiceapplication -Identity “Search Service Application”
  2. Create a new suggestion:
    1. New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ss -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name “SharePoint Server 2010”

Now the next thing you want to do is run a timer job.  The timer job is called Prepare query suggestions and it is scheduled to run once a day.  Run it now to get it to process your suggestion.

One way you can verify if your suggestion was added successfully is to use this PowerShell command:

Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $ss

That will show you the Always Suggest words; of course, you can and should go try it out in the browser as well.  Finally, you may add one and decided that you want to remove it; we can do that too.  Here’s the PowerShell command for that:

Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ss -Language En-Us -Type QuerySuggestionAlwaysSuggest -Identity “SharePoint Server 2010”

Note the main difference is the last parameter name.  When you are adding a suggestion, the last parameter is called “Name”; when you are removing it the parameter is named “Identity”.  Also, don’t forget to run the timer job after you remove an entry.  It may take a few minutes after running the timer job to see the updated results.

 

Advertisements

Why Do I Get an Access Denied Error When Managing User Contexts in SharePoint 2010

User Context is a feature of FAST Search for SharePoint 2010 that is analagous to using audiences with search results.  As you start to test this out you may find that within the site collection you can create FAST keywords and document promotions and demotions, but when you try and manage the User Contexts for the site collection, you get an access denied.  This can happen if your site collection administrator, even if you’re a farm administrator.  So what’s the problem?  Well in order to manage user contexts, you need to have some manage rights in the User Profile service application as well.  The thing that can trip you up is that if you are a farm administrator you do have rights to manage the user profile service, but at least for now, that is not enough.  You need to specifically go into Central Admin…Application Management…Manage Service Applications.  Select your user profile service application and click the Administrators button in the ribbon.  Add your account that you want to be able to manage user contexts, and grant them at least the Manage Profiles right.  Once you save you changes there you should be able to access the manage user contexts page in a site collection.