The pre-query search suggestions feature (“find-as-you-type” functionality in the Search Center) automatically populates a list of keywords using previously searched terms by users. Obviously, this may take a while to compile, so it is a good idea to pre-populate a list of keywords from a CSV file (providing you know what the keywords are of course). This PowerShell script does exactly that. The format of the CSV file must have the word “Suggestion” on the top line and then your keyword list – for example:
SharePoint Server 2010
The script itself looks like this:
#Set up default variables
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application"
#Create Lists from each item in CSV file
$csvData = Import-Csv $csvfile
foreach ($line in $csvData)
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $line.Suggestion
$timerJob = Get-SPTimerJob "Prepare query suggestions"
Note that the we also run the “Prepare query suggestions” Timer job – which normally runs daily – to prepare these suggestions for use in search.