When we start typing the keywords in the SharePoint search box control it internally performs an AJAX call to /_vti_bin/client.svc/ProcessQuery and that calls the stored procedure proc_MSS_GetQuerySuggestions. The proc_MSS_GetQuerySuggestions stored procedure gets the suggestions from the MSSQLogSearchCounts table. This table exist in the Search Service Application Name Database.
How Suggestions are saved?
- Manual ( using code / PowerShell / csv file import from central admin)
- Automatically by prepare query suggestions timer job.
What determines a query suggestion?
- Query suggestions are based on frequently used search terms and click through to results. Listed below are the steps needed for SharePoint to promote a term to a query suggestion.
- The associated Search Service application must have query logging enabled.
- The user must type in a valid word or set of words in the search box.
- The user must click on 6 or more search result links and open or save the file. Some types of pages containing the term can qualify as click-throughs.
- The Query Logging timer job must be run.
- The Prepare Query Suggestions time job must be run.
Some Powershell Operations related to Search Suggestion
Add Single Suggestion
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service App 2"
$owner = Get-SPEnterpriseSearchOwner -Level SSA Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp -Owner $owner New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name "Honda" -Owner $owner Start-SPTimerJob -Identity "prepare query suggestions"
Add More than one Suggestion
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
$SearchSuggestionsList = @("Car", "Honda", "F1")
$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service App 2"
$owner = Get-SPEnterpriseSearchOwner -Level SSA Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp -Owner \$owner
foreach ($Suggestion in $SearchSuggestionsList)
{
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest - Name $Suggestion -Owner \$owner
}
Start-SPTimerJob -Identity "prepare query suggestions"
Get All Search Suggestions
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
\$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service App 2"
$owner = Get-SPEnterpriseSearchOwner -Level SSA Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp -Owner \$owner
Remove Single Search Suggestion
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service App 2"
$owner = Get-SPEnterpriseSearchOwner -Level SSA Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp -Owner $owner
Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest - Identity "Honda" -Owner $owner
Start-SPTimerJob -Identity "prepare query suggestions"