Adding FAST Keywords and Best Bets via Powershell.

Reading the TechNet docs on Add, edit, remove and display keywords by using Windows PowerShell (FAST Search Server 2010 for SharePoint) was a little confusing. Specifically the important note about making sure that you have a Search Settings Group. When you create or find a Search Settings Group you do so using a –Name parameter. The is nothing there to suggest what this Name parameter corresponds to.

However with a PowerShell hacking I found that this name is actually the GUID of the Site Collection for which you want to add keywords and best bets. Now armed with this info I was able to craft up this PowerShell script to do my bidding.

# SharePoint cmdlets
Add-PSSnapin Microsoft.SharePoint.PowerShell
if([Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")-eq$null){throw "Unable to load Microsoft.SharePoint.dll";}

Add-PSSnapin Microsoft.FASTSearch.PowerShell
if([Reflection.Assembly]::LoadWithPartialName("Microsoft.FASTSearch.PowerShell")-eq$null){throw "Unable to load Microsoft.FASTSearch.dll";}

Start-SPAssignment -Global            # This cmdlet takes care of the disposable objects to prevent memory leak.

#get the Search Settings Group for the Site Collection
$site = Get-SPSite -Identity "http://northwindtraders"
$ssg = Get-FASTSearchSearchSettingGroup -Name $site.ID

if($ssg -eq $null)
	#create the ssg if it doesn't exist
	$ssg = New-FASTSearchSearchSettingGroup -Name $site.ID

$keyword = $ssg.Keywords.GetKeyword("snowmobile")
$uri = New-Object -TypeName System.Uri -ArgumentList "http://northwindtraders/products/snowmobiles/pages/snm881.aspx" 
$keyword.AddBestBet("SNM881", "A large sled with plenty of storage", $uri)
$uri = New-Object -TypeName System.Uri -ArgumentList "http://northwindtraders/products/snowmobiles/pages/snm313.aspx" 
$keyword.AddBestBet("SNM313", "Our most powerful sled. Extreme Power!", $uri)

Stop-SPAssignment -Global

Remove-PsSnapin Microsoft.SharePoint.PowerShell
Remove-PSSnapin Microsoft.FASTSearch.PowerShell

This entry was posted in FAST, PowerShell, SharePoint. Bookmark the permalink.

7 Responses to Adding FAST Keywords and Best Bets via Powershell.

  1. Thanks for the article.
    I have a problem in that my FAST Admin server does not have SP installed – and hence no Microsoft.SharePoint.Powershell.dll – and my SP servers don’t have FAST installed. I have registered the Microsoft.FastSearch.Powershell.dll into my SP server, but PS still cannot find it “not registered”. Similar experience on my FAST Admin server. Any ideas? Thanks, Step

  2. Sezai Komur says:

    Use these instead:

    Export FAST Keywords and User Contexts from SharePoint 2010 to CSV

    Import FAST Keywords and User Contexts to Sharepoint 2010 from CSV

  3. gavinbarron says:

    Thanks for those links Sezai!
    They are really useful for adding lots of best bets, I think that my example is really useful to help someone quickly grasp the underlying mechanics and the curly issue of just what that “Name” for the SearchSettingsGroup is.

  4. Sezai Komur says:

    Gavin, agreed – your post helps explain that the Name parameter = Site Collection ID, which is very poorly document!

  5. Ananth says:

    I have added few Fast Search keywords and having the same in Sql Database. How can search those in Fast Search page? Any mappings to be done?

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.