Monday, May 8, 2017

How to enable results from private groups on an Enterprise Search Center

image

Ever since private Office 365 Groups were launched we have been troubled with search in these sites. First it didn't work at all, but later Microsoft made it work in the site itself, in Delve and on the SharePoint home page. Seems they forgot about the Enterprise Search Center.

Note: This is not an issue with Public Office 365 Groups- and seems to work in First release tenants as well

I have previously written about how to get results from private Office 365 Groups using REST, but for the vast majority of people out there you probably want to enable this on your Enterprise Search Center as well. If you have an issue with this, here’s how to make this work.
The gist of it is to set a property on the actual search query named EnableDynamicGroups. This property is hidden inside the DataProviderJSON property of the search result web part definition, and is not that easy to set. The approach taken follows my old post of of turning off duplicate trimming – which later was enabled in the UI.

This time around my sample is using Office PnP PowerShell, but you should be able to adapt it to CSOM if you want, or manually edit the .webpart file if that’s your poison.

The sample assumes your result page is named result.aspx, and that the search results web part is named “Search Results”. Enjoy!

# Result page
$pageUrl = "/sites/enterprisesearch/Pages/results.aspx"

#Check out file
Set-PnPFileCheckedOut -Url $pageUrl
$resultWP = Get-PnPWebPart -ServerRelativePageUrl $pageUrl -Identity "Search Results"
$dataProvider = ConvertFrom-Json $resultWP.WebPart.Properties["DataProviderJSON"]

$ht = @{}
$dataProvider.Properties.psobject.properties | Foreach { $ht[$_.Name] = $_.Value }

$ht["EnableDynamicGroups"] = $true
$dataProvider.Properties = $ht
$dataProvider.PropertiesJSON = ConvertTo-Json $dataProvider.Properties -Compress

$dpJSON = ConvertTo-Json $dataProvider -Compress

# Persist the changes
Set-PnPWebPartProperty -ServerRelativePageUrl $pageUrl -Identity $resultWP.Id -Key "DataProviderJSON" -Value $dpJSON

#Check in file
Set-PnPFileCheckedIn -Url $pageUrl -CheckinType MajorCheckIn