none
Creating Bestbets via powershell, how do I set the various options? RRS feed

  • Question

  • I have this script to create promoted results (best bets)

    But it creates a bestbet using the "advanced query text match" option.

    I want to use the "Query matches keyword exactly".

    When I dig into the objects, I came up with this,

    $queryRules | select -ExpandProperty queryconditions | select id, BoundVariables, MatchingOptions, SubjectTermsOrigin 

    But I am not real sure how to use any of those objects.

    Here is the full script:

    $siteUrl = "http://sandbox0391"
    $resultSourceName = "Local SharePoint Results"
    
    $web = Get-SPWeb $siteUrl
    $ssa = Get-SPEnterpriseSearchServiceApplication "SBX Search Service Application 2"
    $queryRuleManager = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($ssa)
    $site = Get-SPSite $siteUrl
    $searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner -ArgumentList  @([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa,$site.RootWeb)
    $searchObjectFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner)
    $federationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
    $resultSource = $federationManager.GetSourceByName($resultSourceName,$searchOwner)
    $queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter)
    $promotedResultCollection = $ssa.GetBestBets($searchObjectFilter)
    
    function CreatePromotedResult([string]$title, [string]$url, [string]$description)
    {
    		Write-Host "Creating Promoted Result .." $title
            $queryRule = $queryRules.CreateQueryRule($title,$null,$null,$true)
    		[string[]]$keywords = $title.split(' ')
            $keywords += $title		
            $keywordCondition = $queryRule.QueryConditions.CreateKeywordCondition($keywords,$false)
            $queryAction = $queryRule.CreateQueryAction([Microsoft.Office.Server.Search.Query.Rules.QueryActionType]::AssignBestBet)
            #PromotedResult = BestBet
    		$promotedResult = $promotedResultCollection.CreateBestBet($title, $url, $description, $false)
            #Map the best bet to the query action
            $queryAction.BestBetIds.Add($promotedResult.Id);
            #Update the query rule
            $queryRule.Update()
            $queryRule = $null	
    		Write-Host "Created Promoted Result for" $title "Finished"		
    }
    
    CreatePromotedResult "Benefits" "https://URL.com/Pages/OpenEnrollment.aspx" "Benefits page!"


    Joshua Fuente

    Tuesday, November 17, 2015 4:50 PM

Answers

All replies