I have created 3query rules in SharePoint 2013. I need to create query rule group using powershell and and define the ordering . anyone give me the better idea to create query rule group using powershell.
2 Answers
Since you already have the query rules created you have the hard part out of the way. You need to decide for each rule whether you Continue or Stop after each rule is processed. This is the GroupProcessingDirective
. For this sample your Query Rule is $qrPR
.
#Pick Your Owner Scope
$owner = Get-SPEnterpriseSearchOwner -Level Ssa
#Create the filter
$ssaFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($owner)
#Get the Group Collection
$qrGroups = $qrm.GetQueryRuleGroups($ssaFilter)
#Create a Query Rule Group
$newGroup = $qrGroups.CreateQueryRuleGroup("My New Demo Group")
#Add Rule To Group choose Continue or Stop
$newGroup.QueryRules.Add($qrPR,[Microsoft.Office.Server.Search.Query.Rules.GroupProcessingDirective]::Continue)
#Update the group
$newGroup.Update()
There is also an another option (example below). Rules must be added in the order in which they should be prioritized, from highest to lowest.
$searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa
$searchFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner)
$ruleMgr = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($ssa)
$qrCollection = $ruleMgr.GetQueryRules($searchFilter)
$qrgCollection = $ruleMgr.GetQueryRuleGroups($searchFilter)
#Get the created rule
$rule = $qrCollection["My Query Rule"]
#Create a Query Rule Group
$qrGroup = $qrgCollection.CreateQueryRuleGroup("New Group")
#Add rule to group
$rule.MoveToGroup($qrGroup, [Microsoft.Office.Server.Search.Query.Rules.GroupProcessingDirective]::Stop)