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
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell
  2. $SearchServiceApp = Get-SPEnterpriseSearchServiceApplication
  3. $fedmanager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($SearchServiceApp)
  4. $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa
  5. $resultSourceName = "Search"
  6. $urlTemplate = "http://yoursharepointsitename/search?q={searchTerms}&format=rss&Market=en-Us"
  7. $qT = "{searchTerms}"
  8. $ResultSource = $fedmanager.GetSourceByName($resultSourceName, $searchOwner)
  9. if(!$ResultSource){
  10. Write-Host "Result source does not exist. Creating."
  11. $ResultSource = $fedmanager.CreateSource($searchOwner)
  12. }
  13. else { Write-Host "Using existing result source." }
  14. $ResultSource.Name =$resultSourceName
  15. $ResultSource.ProviderId = $fedmanager.ListProviders()['OpenSearch Provider'].Id
  16. $ResultSource.ConnectionUrlTemplate = $urlTemplate
  17. $ResultSource.CreateQueryTransform($queryProperties,$qT)
  18. $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.