Skip to content

Getting a list of all Promoted Results (best bets) in a SharePoint 2013 site collection

01/12/2015

I had a business user ask me the other day if they could see a list of all the best bets in their new 2013 SharePoint portal so that they could validate the terms and links. First off, we know in 2013 that best bets have evolved into Promoted Results. But beyond that, for a business user that does not have access to view the search configuration pages, this was unfortunately not a simple request.

I could give them access to the Query Rule configuration page, and they could scan the query rule table, looking for those items identified as Promoted Results amongst the other types of query rules, however they still can’t see the links to the best bets.

QueryRules

Doing a Bing search will return some scripts that may help you. But many of them only return promoted results from the Search SSA (not from a site collection). I thought I would share what I used in  case it helps someone else. Note, I named all my Query Rules that have promoted results with the prefix “PR:” and that’s how I filter, but of course you can change it to add your own criteria, or none at all.

This script will both list the Promoted Results in the PowerShell Window as well as output the values to a file. Hope it can help you!

Output

$SearchServiceName = “Search Service Application”

$sspApp = Get-SPEnterpriseSearchServiceApplication $SearchServiceName

$siteUrl = “http://myportal/search

$site = get-spsite $siteUrl -WarningAction SilentlyContinue

$web = $site.rootweb

$fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($sspApp)

$SearchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::SPWeb, $web)

$SearchObjectFilter =  New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($SearchOwner)

$queryRuleManager = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($sspApp)

$queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter)

$bestbets = $queryRuleManager.GetBestBets($SearchObjectFilter)

$promotedResults = $queryrules | Where-Object{$_.DisplayName -match “PR”}

$promotedResults | ForEach {

Write-Host “Query Rule Title:  ” -ForegroundColor “Yellow” –NoNewLine

Write-Host   $_.DisplayName -ForegroundColor “White”

Write-Host “Terms: ” -ForegroundColor “Yellow”  –NoNewLine

Write-Host $_.QueryConditions.Terms -ForegroundColor “White”

Write-Host “Best Bet Title(s):” -ForegroundColor “Yellow”   –NoNewLine

Write-Host -ForegroundColor “White”   $_.AssignBestBetsAction.BestBetIds.GetBestBetsFromIds().Title

Write-Host “Best Bet URL(s):”  -ForegroundColor “Yellow” –NoNewLine

Write-Host -ForegroundColor “White”   $_.AssignBestBetsAction.BestBetIds.GetBestBetsFromIds().URL

Write-Output “Query Rule Title: ”   $_.DisplayName

Write-Output “Terms: ”  $_.QueryConditions.Terms

Write-Output “Best Bet Info: ” $_.AssignBestBetsAction.BestBetIds.GetBestBetsFromIds()} >>  c:\output.txt

.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: