Share via


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"
  • 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.

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Thanks!  I needed to do exactly this and remembered seeing this post- very helpful. Any idea how many of these suggestions we can load up?  We're considering adding a few thousand from a customer dataset.  We'll test, but I was wondering if you knew of any upper limit.

  • Anonymous
    May 25, 2010
    Hi thanks, this post was very helpful. Do you know if there is a way to automatically populate this list based on user queries? Manually adding all possible phrases in my installation is impossible. Thanks!

  • Anonymous
    June 10, 2010
    Awesome post! Thanks for the great information!

  • Anonymous
    September 03, 2010
    Thanks for the post.  I'm getting my feet wet in 2010.  Can you confirm the type ahead feature works in Search Enterprise edition?  The not FAST or Not Foundation version.  Currently I'm not getting any per or post type ahead or suggested results...

  • Anonymous
    October 04, 2010
    Thanks  this was helpful. but I have few queries, Can we create only one query suggest in sharepoint 2010. Say for example: I'm creating a query suggest named "A" , and start the timer job. Again if I'm creating another query suggest named "B", and start the timer job.. Then how to differentate which one is running. And also I have a requirement to use many query suggestion. Please help me to clarify this. Thanks!!

  • Anonymous
    February 17, 2011
    The comment has been removed

  • Anonymous
    April 05, 2011
    The comment has been removed

  • Anonymous
    November 17, 2011
    We had problems with Query Suggestions not populating automatically. Spent weeks even months trying to get it working, including Microsoft Support getting involved (they could reproduce the issue, but did not know how to fix it.) Turns out at some stage Query Logging was disabled on the Search Service Application. It would be nice if more sites mentioned the relationship. (I'm posting this here just in case somebody else has this problem!)

  • Anonymous
    September 18, 2014
    The comment has been removed