Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to Configure SharePoint Search Suggestions using Powershell - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2013-05-02

Search Suggestion is one of the cool features available in the SharePoint 2010 and SharePoint 2013. The search query will automatically appear in the search box drop down, when the user clicks the search result at-least 6 times in the search result page.

In this post, we will see how to add or import the search suggestion terms manually using the Powershell cmdlets.

Requirements:

Initialize and get an instance of the Search Service Application

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$SearchServiceApplicationName = "Search Application"
$SearchServiceApplicationProxyName = "Search Service Application Proxy 1"
$SiteUrl = "http://win-2j3idcdeuh6/"
$RootSiteCollection = Get-SPSite $SiteUrl -ErrorAction SilentlyContinue
#-----------------------------------------------------
# Get the Search Service application
#-----------------------------------------------------
$SearchServiceApplicationProxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceApplicationProxyName
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceApplicationName -ErrorAction SilentlyContinue
$FederationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($SearchServiceApplicationProxy)

#--------------------------------------------------------------------------
# The below line creates a Search Object owner at the site collection level
# and this can be changed to Search Application or Site level by passing
# different SearchObjectLevel argument.
#--------------------------------------------------------------------------
$RootSiteCollection = Get-SPSite $SiteUrl -ErrorAction SilentlyContinue
$SearchOwner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $RootSiteCollection.RootWeb

Set the default Search Result source

$ResultSourceName ="Local SharePoint Results"
$ResultSource = $FederationManager.GetSourceByName($ResultSourceName,$SearchOwner)
if($ResultSource)
{
#-----------------------------------------------------------
# Update the new Search source as a default one...
#-----------------------------------------------------------
$ResultSource = $FederationManager.UpdateDefaultSource($ResultSource.Id,$SearchOwner)
}
else
{
Write-Host "Result Source : $ResultSourceName does not exist".
}

Add a new set of Search Phrase

# Get the existing phrase list...
$PhraseList = Get-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $SearchServiceApplication -Owner $SearchOwner -SourceId $ResultSource.Id
# Remove all the existing phrase for the give search result resource ...
$PhraseList | Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $SearchServiceApplication -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $SearchOwner -SourceId $ResultSource.Id

# Add the new phrase...
New-SPEnterpriseSearchLanguageResourcePhrase -Name "SharePoint Community" -SearchApplication $SearchServiceApplication -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $SearchOwner -SourceId $ResultSource.Id
New-SPEnterpriseSearchLanguageResourcePhrase -Name "SharePoint Search" -SearchApplication $SearchServiceApplication -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $SearchOwner -SourceId $ResultSource.Id
New-SPEnterpriseSearchLanguageResourcePhrase -Name "SharePoint Search suggestion" -SearchApplication $SearchServiceApplication -Type QuerySuggestionAlwaysSuggest -Language "en-us" -Owner $SearchOwner -SourceId $ResultSource.Id

Import a new set of Search Phrase

# Import the popular queries from the given txt file...
Import-SPEnterpriseSearchPopularQueries -SearchApplicationProxy $SearchServiceApplicationProxy -Filename "E:\work\SharePoint\Search\SP2013 - QuerySuggestion.txt" -ResultSource $ResultSource -Web $RootSiteCollection.RootWeb -Verbose

Note: The import file contains Query terms, Query count, Click count and the LCID. The display order in the suggestion list is determined by  the “Query count” and the “Click count”.

example : “SharePoint Community – Txt File,1100,1180,1033”

Run the “PrepareQuerySuggestionsJobDefinition” timer job

$TimerJob = Get-SPTimerJob -type "Microsoft.Office.Server.Search.Administration.PrepareQuerySuggestionsJobDefinition"
$TimerJob.RunNow()

Search Suggestion UI

Search Suggestion Client / Database

The Search control makes a ajax call (/_vti_bin/client.svc/ProcessQuery) which in turn calls the “proc_MSS_GetQuerySuggestions” stored procedure (“MSSQLogSearchCounts” table – stores the terms and  Query and Click Count) to get the Search suggestion.

The full search suggestion configuration script and the text file can be downloaded from here.

(Visited 577 times, 1 visits today)

About the author 

Balamurugan Kailasam

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.