Auto populate Search suggestions for SharePoint People Search

One of mine customers wanted to replace their existing phone directory with the SharePoint OOTB user profiles. They already had all the data in the Active Directory and also had pictures for most employees, so SharePoint sounded like an obvious choice. One of the requests was to have search as you type suggestions for people search. The good news is: this already exists in SharePoint, you just just need some PowerShell magic to work correctly.

SharePoint People Search As You Type

A note from the official documentation:

Query suggestions depend on users' searches. Only search queries that have been previously returned and then clicked through at least six times will appear in either the search box list or the Related Queries Web Part. Therefore, a newly deployed SharePoint Server 2010 system will not show query suggestions in either location. Moreover, a query suggestion will only appear in the search box list or the Related Queries Web Part if the query suggestion contains at least one of the words that are typed.

This is what you need to do to configure this for your environment:

1. Execute the following script in your environment. For parts of this script I used this script by Daniel Root). Make sure you change to match your Search Service Application name (line 22) before exacting.

cls if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) { 	Add-PSSnapin Microsoft.SharePoint.PowerShell; } function Enumerate-SPUserProfiles($SearchServiceApp) { 	$x= [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 	$x= [System.Reflection.Assembly]::LoadWithPartialName("microsoft.sharepoint.portal") 	$x= [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") 	$x= [System.Reflection.Assembly]::LoadWithPartialName("System.Web") 	$sites = Get-SPSite 	$context = [Microsoft.Office.Server.ServerContext]::GetContext($sites[0]) 	$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 	# gets all the user profiles, those that have domain\username as DisplayName are excluded 	$profileManager.GetEnumerator() | ?{$_.DisplayName -notlike '*\*' } | foreach-object { Add-SPSuggestion $SearchServiceApp $_ } | } function Add-SPSuggestion($SearchServiceApp, $User) { 	New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name $User.DisplayName } #Change to match your Search Service Application Name $searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application" Enumerate-SPUserProfiles Start-SPTimerJob -Identity "prepare query suggestions" 

2. Navigate to your Search Center > People Search page

3. Edit People Search Web Part properties

4. Check the Show query suggestion option

Show Query Suggestions

5. Save Page

That's it! You are done!