Skip to content

Instantly share code, notes, and snippets.

@ishajain
Created March 30, 2014 23:39
Show Gist options
  • Select an option

  • Save ishajain/9881879 to your computer and use it in GitHub Desktop.

Select an option

Save ishajain/9881879 to your computer and use it in GitHub Desktop.
rite-Host "setting up the site collection level result souce for the site" -ForegroundColor yellow
$resultSourceName="MyResultSource"
$resultSourceDescription ="site collection result source"
$query="{searchTerms?} Path:{SiteCollection.Url}"
$ssa = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
$fedman = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
$searchOwner = Get-SPEnterpriseSearchOwner -SPWeb $web -Level SPSite
$resultSource = $fedman.GetSourceByName($resultSourceName, $searchOwner)
#Check To See if it exists
if(!$resultSource){
$resultSource = $fedman.CreateSource($searchOwner)
}
$resultSource.Name =$resultSourceName
$resultSource.ProviderId = $fedman.ListProviders()['Local SharePoint Provider'].Id
$resultSource.Description = $resultSourceDescription
$resultSource.CreateQueryTransform($query)
$resultSource.Commit()
Write-Host "Settings the Site Collection scope for the search results in the Search Results webpart" -ForegroundColor yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment