SharePoint Search Query Suggestions
Search suggestions is one of the great new feature introduced in SharePoint 2010, enhanced in SharePoint 2013. Search query suggestions are words that appear under the search box as users type a search query. (also known as Pre-query suggestions).
SharePoint Search suggestions are automatically generated:
When users have clicked any of the search results for that query at least six times, then that query will be automatically added to search suggestions. Technically, on a daily basis, the SharePoint timer job titled “Prepare Query Suggestions” handles compiling them. So the automatic query suggestions can be different for different result sources and site collections.
Although Search query suggestions are auto-populated based on user searches, It would be helpful to manually add search query suggestions to promote specific areas of your SharePoint. Isn’t it?
How to Add SharePoint 2013 Search Suggestions using PowerShell?
Let’s add SharePoint 2010 search suggestions with PowerShell script.
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
#Set the Terms to add in Search Suggestions
$SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")
#Get the Search Service Application "Search Service Application" - Your's maybe in a different name
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application"
#Process Each Search Term
foreach ($Suggestion in $SearchSuggestions)
{
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $Suggestion
}
#Trigger the Timerjob
$timerJob = Get-SPTimerJob "Prepare query suggestions"
$timerJob.RunNow()
Instead of having them in a hard-coded array, Its also possible to have them in a CSV file and import them:
$csvfile = "D:\SearchSuggestions.csv" #with header "Suggestion"
$KeyWordsData = Import-Csv $csvfile
...
foreach ($Row in $KeywordsData)
{
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $Row.Suggestion
}
...
You can get the Search service application name by navigating to central admin and manage service applications page.
Result: As a user types keywords in the Search box, the Search Center provides suggestions to help complete the query
To Get all SharePoint 2013 search query suggestions:
#Get the Search Service Application "Search Service Application" by its name
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application"
#Get all Search Query suggestion
Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $ssa
Remove a Search Suggestion using PowerShell:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
#Get the Search Service Application "Search Service Application" by its name
$ssa = Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application"
#Remove Search Query Suggestion "Crescent Employee Of the Month"
Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Identity "Crescent Employee Of the Month"
#Trigger the Timerjob for the changes to take effect
$timerJob = Get-SPTimerJob "Prepare query suggestions"
$timerJob.RunNow()
How to Add SharePoint 2013 search query suggestions manually:
Go to Central Administration >> Manage service applications >> Search Service Application >> Click on Query Suggestions link from left navigation. From here, you can enable/disable, Import/Export your custom search query suggestions.
BTW, importing query suggestions overwrites any existing manual query suggestions created already! So, Export them first, modify and then import again!!
Whats new in SharePoint 2013 search query suggestions:
Things are slightly different in SharePoint 2013, as it allows customizing Search parameters at SSA/Site collection/Site level. So, We’ve an additional parameter “Owner” to specify the scope. Also, query suggestions have improved in SharePoint 2013 with result sources. The query suggestions are generated daily for each result source – each site collection.
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
#Set the Terms to add in Search Suggestions
$SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")
#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
#You can also use: Get-SPEnterpriseSearchServiceapplication -Identity "Search Service Application"
$owner = Get-SPEnterpriseSearchOwner -level SSA
#Process Each Search Term
foreach ($Suggestion in $SearchSuggestions)
{
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name $Suggestion -Owner $owner
}
#Trigger the SharePoint 2013 query suggestions timer job
Start-SPTimerJob -Identity "Prepare query suggestions"
Don’t forget to Run the SharePoint 2013 query suggestions timer job!
Remove Search Suggestions at SSA level in SharePoint 2013:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
#Set the Query Suggestion Level
$owner = Get-SPEnterpriseSearchOwner -level SSA
#Get All Existing phrases
$SuggestionList = Get-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Owner $Owner -Language En-Us -Type QuerySuggestionAlwaysSuggest #-SourceId $ResultSource.Id
#Remove Them All
$SuggestionList | Remove-SPEnterpriseSearchLanguageResourcePhrase -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $Owner
#Trigger the SharePoint 2013 query suggestions timer job
Start-SPTimerJob -Identity "Prepare query suggestions"
Add Query Suggestions at Site Level in SharePoint 2013:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
#Set the Terms to add in Search Suggestions
$SearchSuggestions = @("Crescent", "Crescent Policies", "Crescent News", "Crescent Tech", "Crescent Employee Of the Month", "Crescent Travel Request")
#Get the default search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
$Web = Get-SPweb -Identity "https://sharepoint.crescent.com/sites/operations/"
$owner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $web
$FederationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager -ArgumentList $ssa
$ResultSource = $FederationManager.GetSourceByName("Local SharePoint Results", $owner)
#Process Each Search Term
foreach ($Suggestion in $SearchSuggestions)
{
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssa -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name $Suggestion -Owner $owner -SourceId $ResultSource.Id
}
#Its also possible to use PowerShell to Import Search Suggestions from text file using PowerShell
#$ssap = Get-SPEnterpriseSearchServiceApplicationProxy
#Import-SPEnterpriseSearchPopularQueries -SearchApplicationProxy $ssap -Filename "D:\querySuggestions.txt" -ResultSource $source -Web $web
#Trigger the timer job
Start-SPTimerJob -Identity "Prepare query suggestions"
That is it! you have added a query suggestion to your SharePoint search box. Now you start typing SharePoint it will bring SharePoint suggestions.
Hello –
Very informative article . keep it up!! . Do you know if the users leave the company when their profiles deleted from user profile .But in query suggestion still i can see their names , if i just type their first name and last name . Though i cannot search their profile when click on search button .
But i want to solve how query suggestion should stop qeuerying deleted profiles .
I am not able to upload a suggestion text file. Its throwing an error duplicate entries found even if I try to upload a completely blank file.