This blog post describes how to create a search result source using PowerShell in SharePoint 2013. I have a requirement to add additional search rules which will be used with the keywords entered by the user in the search box, then you will need to create custom search result sourc
sample query
The query will be,
{searchTerms} Author={User.Name} FileType=pdf FileType=docx
Source Code
- Add-PSSnapin Microsoft.SharePoint.PowerShell
-
- $SearchServiceApp = Get-SPEnterpriseSearchServiceApplication
- $fedmanager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($SearchServiceApp)
-
- $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa
-
- $resultSourceName = "Search"
- $urlTemplate = "http://yoursharepointsitename/search?q={searchTerms}&format=rss&Market=en-Us"
- $qT = "{searchTerms}"
- $ResultSource = $fedmanager.GetSourceByName($resultSourceName, $searchOwner)
- if(!$ResultSource){
- Write-Host "Result source does not exist. Creating."
- $ResultSource = $fedmanager.CreateSource($searchOwner)
- }
- else { Write-Host "Using existing result source." }
-
- $ResultSource.Name =$resultSourceName
- $ResultSource.ProviderId = $fedmanager.ListProviders()['OpenSearch Provider'].Id
- $ResultSource.ConnectionUrlTemplate = $urlTemplate
- $ResultSource.CreateQueryTransform($queryProperties,$qT)
- $ResultSource.Commit()
Conclusion
Was my blog helpful? If yes, please let me know and if not, please explain what was confusing or missing. I’ll use your feedback to double-check the facts, add info, and update this blog.