Microsoft Cloud Authors: Nick Basinger, Kevin Benedict, Pat Romanski, Liz McMillan, Lori MacVittie

Related Topics: Microsoft Cloud, Silverlight

Microsoft Cloud: Blog Feed Post

Query People Search in SharePoint Online

(and other SharePoint platforms too!)

At my Search talk at SPC11, I demoed how to build a Silverlight application that could query search in SharePoint Online.  I also built a separate application that could query people search, but I haven’t posted on it yet until today.  To query people search, we have to know a few things about how SharePoint operates.  It all starts with understanding the scopes involved.  If you take a look at your Search Scopes link in your site collection settings, you’ll see a similar list to the one below.


What’s funny here is that SPO actually returns item counts for the entire (non-partitioned index).  This tells me that there are 205,000 items and 96,000 people on my particular Office 365 SharePoint host.

Ultimately, querying people search is just a matter of executing a query against the scope People, but there are a few catches.  In SharePoint 2007, you could actually execute the query Scope:”People” on a results.aspx with a CoreResultsWebPart and you would actually get results.  It wouldn’t display pictures or additional user information such as department or phone number, but it would work.  With the introduction of federated search in SharePoint 2010, people search now gets executed by it’s own federated location named LocalPeopleSearchIndex (see my post on the QueryManager class for more information).  This means that a regular CoreResultsWebPart will not return results for Scope:”People” no matter what you do.


However, a PeopleCoreResultsWebPart will.


Issuing the query Scope:”People” will return every user in the user profile store.  Including service accounts like you see above.  The fact that I couldn’t issue a people search query to the regular CoreResultsWebPart actually threw me off for quite some time.  It just didn’t make sense to me what was going on behind the scenes.  It didn’t become ultimately clear, until I tried issuing the query to Search.asmx.  The Scope:”People” query works just fine when calling the web service.  Today you will learn how to query people search using the web service.  I’m going to use the exact same application I have been using with my other search demos, we’ll just tweak the input a little bit.

For today’s example, I am going to build off of the Silverlight 4 application I used at SPC.  I’m using Silverlight, but you could just as well write a console application or call this web service from some other ASP.NET application.  We still want to start by creating a service reference to /_vti_bin/search.asmx. We then create an instance of the web service so that we can use it.  We also bind an event handling method to handle the results of the web service call.

QueryServiceSoapClient queryService = new QueryServiceSoapClient();

queryService.QueryExCompleted += new EventHandler<QueryExCompletedEventArgs>(QueryService_QueryExCompleted);

Once we have a reference to the web service, it’s just a matter of constructing the input XML document and sending it to the web service.  For SharePoint Online and SharePoint 2010, we actually don’t have to change any of the XML at all. We just need to change the query. That means our input will look like the following.  Note, we’re using a type of STRING (even if using FAST Search for SharePoint).

<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">

<Query domain="QDomain">





<QueryText language="en-US" type="STRING">Scope:"People"</QueryText>




If we are using FAST Search for SharePoint, we need to add to a ResultProvider element inside the Query element.  Remember, People Search is handled by the SharePoint 2010 search engine in FAST Search for SharePoint.





Just like before, I assemble this XML string using a StringBuilder.  I allow the user to type in a query and I just automatically append Scope:”People” to the query ensuring we only get people results.

StringBuilder queryXml = new StringBuilder();


queryXml.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");

queryXml.Append("<Query domain=\"QDomain\">");







queryXml.Append("<QueryText language=\"en-US\" type=\"STRING\">");

queryXml.AppendFormat("{0} Scope:\"People\"", SearchTextBox.Text);







We’ll then bind the resulting XML to a textbox so that we can look at the results.

ResultsTextBox.Text = e.Result.Nodes[1].ToString();

That’s all that is involved in this first round of code.  Compile the code and upload the Silverlight application to a document library and use the Silverlight web part just like before.  If you want more details on how the above code works, be sure and check out the original Search with Silverlight 4 post.   Let’s take a look at the results.  Here’s the application running.


I issues a query and I got results.  Let’s look at the XML in the results a bit more though.

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

<Results xmlns="">

<RelevantResults diffgr:id="RelevantResults1" msdata:rowOrder="0">



<Title>Craig Johnson</Title>






<HitHighlightedSummary />

<HitHighlightedProperties>&lt;HHTitle&gt;Craig Johnson&lt;/HHTitle&gt;&lt;HHUrl&gt;https://dotnetmafia-my.sharepoint.com/Person.aspx?accountname=i%3A0%23.f|membership|craig.johnson%40dotnetmafia.onmicrosoft.com&lt;/HHUrl&gt;</HitHighlightedProperties>



<PictureThumbnailURL>https://dotnetmafia-my.sharepoint.com/User Photos/Profile Pictures/[email protected]_MThumb.jpg</PictureThumbnailURL>


We have the user’s name in the Title field and we have some links to a picture and the user’s profile.  For the most part though, these fields aren’t entirely useful.  That’s because SharePoint treats this result as a regular document result instead of a person.  If we want useful information about the user, we have to ask for that information in our original query.  Specifically, we need to specify the names of the managed properties that we want returned (i.e.: JobTitle and Department).  How do we know what the names of those properties are?  In SharePoint 2010, we can just go look in the search service application.  However, we don’t have that option in SharePoint Online.  There’s another way though.  Go back to your PeopleResults.aspx page in your Search Center and edit it.  Then, you need to modify the PeopleCoreResultsWebPart.  Expand Display Properties and then uncheck Use Location Visualization.  The contents of the XML in Fetched Properties has the answer.


Here is what the XML looks like.


<Column Name="WorkId"/>

<Column Name="UserProfile_GUID"/>

<Column Name="AccountName"/>

<Column Name="PreferredName" HitHighLight="true"/>

<Column Name="YomiDisplayName" HitHighLight="true"/>

<Column Name="JobTitle" HitHighLight="true"/>

<Column Name="Department" HitHighLight="true"/>

<Column Name="WorkPhone" HitHighLight="true"/>

<Column Name="OfficeNumber" HitHighLight="true"/>

<Column Name="PictureURL"/>

<Column Name="HierarchyUrl"/>

<Column Name="WorkEmail" HitHighLight="true"/>

<Column Name="Path"/>

<Column Name="HitHighlightedSummary"/>

<Column Name="HitHighlightedProperties"/>

<Column Name="Responsibility" HitHighLight="true"/>

<Column Name="Skills" HitHighLight="true"/>

<Column Name="SipAddress" HitHighLight="true"/>

<Column Name="Schools" HitHighLight="true"/>

<Column Name="PastProjects" HitHighLight="true"/>

<Column Name="Interests" HitHighLight="true"/>

<Column Name="OrgNames" HitHighLight="true"/>

<Column Name="OrgUrls"/>

<Column Name="OrgParentNames" HitHighLight="true"/>

<Column Name="OrgParentUrls"/>

<Column Name="Memberships" HitHighLight="true"/>

<Column Name="AboutMe" HitHighLight="true"/>

<Column Name="BaseOfficeLocation" HitHighLight="true"/>

<Column Name="ServiceApplicationID"/>

<Column Name="SocialDistance"/>


This gives you quite a few choices to display in your results.  The column names are pretty self explanatory.  Now, we just have modify our input XML to specify which managed properties we want.  Do you remember how to specify managed properties with the Search web service?  If not, we start by adding a Properties element inside the Query element.  We then add a Property element for each managed property.  One thing to remember is that the managed properties must be specified in lower case.  You will get a NotFound exception if they are not.  Here is an example:


<Property name="accountname" />

<Property name="preferredname" />

<Property name="jobtitle" />

<Property name="department" />

<Property name="workphone" />

<Property name="officenumber" />

<Property name="pictureurl" />

<Property name="workemail" />


Remember, once you specify any column, you must specify every column you want.  The default columns will no longer be returned.  When we recompile, upload the new application, and execute a query again, we now get much better results.

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

<Results xmlns="">

<RelevantResults diffgr:id="RelevantResults1" msdata:rowOrder="0">

<accountname>i:0#.f|membership|[email protected]</accountname>

<preferredname>Craig Johnson</preferredname>


<department>Accounts Receivable</department>



<pictureurl>https://dotnetmafia-my.sharepoint.com/User Photos/Profile Pictures/[email protected]ia.onmicrosoft.com_MThumb.jpg</pictureurl>

<workemail>[email protected]</workemail>


You can query with these same managed properties as well.  For example, I could use the department managed property to see who is in Accounting with the following query.



Maybe, you want to look up who the CEO of the company is.  To do that use the jobtitle managed property.  Resist the urge to capitalize the words in the managed property.  They must be in lower case.  Note: that the title managed property is reserved for personal titles such as Jr., Sr. etc.



Now, that we can query with all of these properties, we can make a nice advanced people search application.  In my demo at SPC11, I used the Telerik RadGridView control to display the user information along with the picture from the user profile.  Here’s a screenshot of what the application looked like.


You can use the same techniques that I detailed in the Advanced Search with Silverlight 4 post to build a people search application like the one above.  This code will work on-premises (SharePoint 2010 or FAST Search for SharePoint) or in the cloud with SharePoint Online.  I’ve confirmed this works with both the P1 and E3 SKUs of Office 365.

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is an independent consultant specializing in Cloud technologies such as Azure and Office 365. He also specializes in mobile development. Corey serves as the product manager for two cloud-first mobile app platforms: BrewZap and HappenZap.

IoT & Smart Cities Stories
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
Chris Matthieu is the President & CEO of Computes, inc. He brings 30 years of experience in development and launches of disruptive technologies to create new market opportunities as well as enhance enterprise product portfolios with emerging technologies. His most recent venture was Octoblu, a cross-protocol Internet of Things (IoT) mesh network platform, acquired by Citrix. Prior to co-founding Octoblu, Chris was founder of Nodester, an open-source Node.JS PaaS which was acquired by AppFog and ...
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...