SharePoint 2013–Search Query Suggestions

2017-12-11T10:28:41+00:00 October 2nd, 2013|PowerShell, Sharepoint|

Just a quick self-note that might come in useful for others. To quote TechNet on configuring Search Query Suggestions in PowerShell for SharePoint 2013: “Use the Get-SPEnterpriseSearchQuerySuggestionCandidates cmdlet to return a list of popular queries that can be displayed in a related queries Web Part. The list gives the administrator a chance to review potential queries and add some of them to the related queries list.

Under the example, we are given the following cmdlet to return popular search queries from the Search Service Application:

$searchapp = Get-SPEnterpriseSearchServiceApplication
Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp

However, the parameters table shows –Owner as “required” which is missing from the example, thus leading to a prompt in our PowerShell session:

cmdlet Get-SPEnterpriseSearchQuerySuggestionCandidates at command pipeline
 position 1
 Supply values for the following parameters:
 Owner:

So, a quick dive into MSDN for the SearchObjectOwner members and we can see our options for the properties. Therefore, I would propose retrieving the Query Suggestions as follows:

$searchapp = Get-SPEnterpriseSearchServiceApplication
 $site = Get-SPSite http://search
 $searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa, $site.RootWeb)
 Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $searchapp -Owner $searchOwner