none
So how do I create a result source using powershell?? RRS feed

Answers

  • Hi Warren,

    There is no PowerShell cmdlet available at this time, but it can still be accomplished by loading the Microsoft.Office.Server.Search assembly in the PowerShell session and utilizing several objects and methods from it. If you still need a solution, I have blogged about it here.


    Kind Regards,
    Teodora Gancheva

    blog: Tips on technology

    • Marked as answer by Warren Roscoe Monday, March 11, 2013 9:56 AM
    Monday, March 11, 2013 8:11 AM

All replies

  • I was just looking myself and there doesn't appear to be one.  I am floored.

    Corey Roth - SharePoint Server MVP blog: www.dotnetmafia.com twitter: @coreyroth | SP2 Apps

    Friday, January 4, 2013 3:52 PM
    Answerer
  • Hi Warren,

    There is no PowerShell cmdlet available at this time, but it can still be accomplished by loading the Microsoft.Office.Server.Search assembly in the PowerShell session and utilizing several objects and methods from it. If you still need a solution, I have blogged about it here.


    Kind Regards,
    Teodora Gancheva

    blog: Tips on technology

    • Marked as answer by Warren Roscoe Monday, March 11, 2013 9:56 AM
    Monday, March 11, 2013 8:11 AM
  • Here you go sir,

    $SearchServiceName = "Search Service Application"

    $ssa = Get-SPEnterPriseSearchServiceApplication -Identity $SearchServiceName
    $fedman = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
    $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa  

    $resultSourceName = "Custom Search"
    $q = '{?{searchTerms} -ContentClass=urn:content-class:SPSPeople Path:{SiteCollection.URL}} (IsDocument:"True" OR contentclass:"STS_ListItem")'
    $queryProperties = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties
    $sortCollection = New-Object Microsoft.Office.Server.Search.Query.SortCollection
    $sortCollection.Add("Title", [Microsoft.Office.Server.Search.Query.SortDirection]::Ascending)
    $queryProperties["SortList"] = [Microsoft.Office.Server.Search.Query.SortCollection]$sortCollection

    $resultSource = $fedman.CreateSource($searchOwner)
    $resultSource.Name = $resultSourceName
    $resultSource.ProviderId = $fedman.ListProviders()['Local SharePoint Provider'].Id
    $resultSource.CreateQueryTransform($queryProperties,$q)
    $resultSource.Commit()

    This creates a custom search result source. This searches for documents in the current site collection and sorts the results by Title.

    Hope this helps.

    Paul.

    • Proposed as answer by Eric Fang Wednesday, November 11, 2015 9:48 PM
    Monday, January 20, 2014 1:52 PM