How to: Seed Search Suggestions in SharePoint 2013 Preview

Posted Tuesday, September 18, 2012 3:17 PM by CoreyRoth

I was digging through some new PowerShell cmdlets for one of my talks coming up at SharePoint Conference 2012 (SPC12), and I stumbled upon the new cmdlet Import-SPEnterpriseSearchPopularQueries.  I found this cmdlet to be interesting since it can be used to easily seed what shows up in the search suggestions on a given site.  I took the example there and did some tweaking and thought I would share my results. 

We first, need to get a reference to the Search Service Application Proxy using Get-SPEnterpriseSearchServiceApplicationProxy.  Sorry, the cmdlets for search a bit wordy so that is what the Tab key is for. :)

$ssap = Get-SPEnterpriseSearchServiceApplicationProxy

Search suggestions are actually specific to the result source and site that hosts the search box.  This means you could have different suggestions depending on which part of the site you are on.  To achieve that, we need to get a reference to the web hosting the search center and ultimately a result source object.  Let’s get the web first.  Change the URL to match your server’s search center.

$searchWeb = Get-SPWeb -Identity http://myserver/search

Now, we will use the Federation Manager to get a result source.  However, we need a Search Object Owner first.  The example on TechNet requires a lot more typing.  I luckily found the cmdlet Get-SPSearchObjectOwner.  It takes a scope (Level) and an SPWeb object.

$owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $searchWeb

Unfortunately, I couldn’t find a command to directly get a result source so that means we actually have to go through the API to get a Federation Manager first.

$mgr = new-object Microsoft.Office.Server.Search.Administration.Query.FederationManager -ArgumentList $ssap

Once we have the manager object, we use the GetSourceByName method passing it the name of the result source and $owner.  In this case, we use “Local SharePoint Results" as the result source name.

$source = $mgr.GetSourceByName("Local SharePoint Results", $owner)

As far as the query suggestions themselves, we will need to create a CSV file with the data.  The format is simple: Query Text,Query Count,Click Count,LCID.  For example:

SharePoint Conference,500,300,1033

Setting these values allows you to control the order in which items appear in the query suggestions.  For suggestions to appear in the search box, the click count must be at least 5.  1033 is the LCID value for English.  Here is what my file looks like:


Now, we run the Import-SPEnterpriseSearchPopularQueries cmdlet.  It needs the SearchApplicationProxy, Filename, and ResultSource parameters which we retrieved with the previous lines of script.

Import-SPEnterpriseSearchPopularQueries -SearchApplicationProxy $ssap -Filename .\suggestions.csv -ResultSource $source -Web $searchWeb

If all commands execute successfully, you should not see anything returned at the command prompt.  Now, you can begin using your suggestions right away.  You do not need to recrawl.  Go to the search center that you specified in your $searchWeb object.  Start typing some of the values from your suggestions and you will see them beneath the search box.


This new PowerShell cmdlet makes it so easy to seed your search suggestions.  I think I will start recommending this on new deployments to really improve the immediate value of search.  Try it out today.


# How to: Seed Search Suggestions in SharePoint 2013 Preview - Corey Roth [MVP] | SharePoint 2013\SharePoint 15 |

Pingback from  How to: Seed Search Suggestions in SharePoint 2013 Preview - Corey Roth [MVP] | SharePoint 2013\SharePoint 15 |

# re: How to: Seed Search Suggestions in SharePoint 2013 Preview

Thursday, November 29, 2012 10:45 AM by Step van Schalkwyk

Thanks Corey

Has anyone succeeded in _removing_ seeds? I've uploaded empty files etc., to no avail.



# re: How to: Seed Search Suggestions in SharePoint 2013 Preview

Thursday, November 29, 2012 2:38 PM by Step van Schalkwyk

#Removing Search Suggestions


$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search"

$searchWeb = Get-SPWeb -Identity http://*.*.com/search

$owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $searchWeb



#Create Lists from each item in CSV file

$csvData = Import-Csv $csvfile

foreach ($line in $csvData)


#Write-Host $line.Suggestion

   Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Identity $line.Suggestion -Owner $owner


$timerJob = Get-SPTimerJob "Prepare query suggestions"


Leave a Comment