Wednesday, June 15, 2011

Clearing items from a specific content source

On your Search Service Application, that be the standard SharePoint Search or FAST for SharePoint has a link called Index Reset which will clear all the searchable items in your index.

For FAST Search for SharePoint you would have to call Clear-FASTSearchContentCollection on the FS4SP farm as well via PowerShell.

This is all fine if you want to remove everything, but sometimes you may want to only remove parts of the index, say only items from a particular content source like SharePoint or your file server.


The trick to achieve this is to remove the start addresses from a search location, and then re-add them. When you remove a start address from a content source, it triggers a delete mechanism which will remove all items from that particular start address.

Here’s a sample PowerShell script which will remove all items from my File server content source called File residing on my Search Service Application called FASTContent. Probably something to turn into a .ps1 file or a cmdlet.

$sourceName = "File"

$contentSSA = "FASTContent"

$source = Get-SPEnterpriseSearchCrawlContentSource -Identity $sourceName -SearchApplication $contentSSA

$startaddresses = $source.StartAddresses | ForEach-Object { $_.OriginalString }


ForEach ($address in $startaddresses ){ $source.StartAddresses.Add($address) }