For instance, I have 3 site collections and all site collections under same database as shown below.
http://spdev5:8004 (root site colection 1)
http://spdev5:8004/sites/site2 (site collection 2)
http://spdev5:8004/sites/site3 (site collection 3)
By default when I search in the root site collection it displays results from all site collections. For ex if I search something in the root site collection it is showing data of site col2 and site col 3 as well. However if search anything in site col2 or site col3 results are limited to that site collection only. That’s fine.
Below script will create a scope in the central admin and you can see this one in the site collection as well.
In the scope I am including my root level site and excluding site collection2.
$searchServiceName="Search Service Application"
$docLibraryURL = “sitecoll2url”
$ssa = Get-SPEnterpriseSearchServiceApplication –Identity $searchServiceName | New-SPEnterpriseSearchQueryScope -Name $scopeName -Description "Include root site collection and Exclude rest of the site collections" -DisplayInAdminUI $true
$scope = Get-SPEnterpriseSearchQueryScope -SearchApplication $searchServiceName -Identity $scopeName
$rule1 = New-SPEnterpriseSearchQueryScopeRule -RuleType "Url" -Url $siteURL -MatchingString $siteURL -FilterBehavior "Include" -UrlScopeRuleType "Folder" -scope $scope
$rule2 = New-SPEnterpriseSearchQueryScopeRule -RuleType "Url" -Url $docLibraryURL -MatchingString $docLibraryURL -FilterBehavior "Exclude" -UrlScopeRuleType "Folder" -scope $scope
Write-Host "Scope Created"
#This scope name (MyScope) you have to update in the root site collection search results page #‘OSSSearchResults.aspx’. just look for ‘Scope’ and update as ‘Scope= MyScope’
# for more info