Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

Full Text Search – search.asmx – User Profile Title field??

Continuing with my Google Maps V3 dashboard using JQuery and AJAX, and a little bit of CorasWorks Data Integration Toolset (DIT).  My next challenge was that when you click on a location in the InfoWindow, it brings up a pane to the left of the map with details in it.

Well, in those details, I wanted to show all of the people that were related to that Location by a custom profile property in their SharePoint User Profile – i.e. all the employees of that location.

So I chose to use the search.asmx web service to perform a full text query on the People scope.  I searched around on Google and I found the following example:

function initializeUserProfileInfo(location)
{
	var userSearchQueryString =
              '<QueryPacket xmlns="urn:Microsoft.Search.Query">
                   <Query>
                         <SupportedFormats>
                               <Format>urn:Microsoft.Search.Response.Document:Document</Format>
                         </SupportedFormats>
                         <Context>
                               <QueryText type="MSSQLFT" language="en-us">
                                      select preferredname, firstname, lastname, workemail, workphone,
                                      title, department, pictureurl, description from scope() where
                                      "scope" = \'People\' order by preferredname
                               </QueryText>
                         </Context>
                         <Range>
                               <StartAt>1</StartAt>
                               <Count>10000</Count>
                         </Range>
                         <EnableStemming>true</EnableStemming>
                         <TrimDuplicates>true</TrimDuplicates>
                         <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
                         <ImplicitAndBehavior>true</ImplicitAndBehavior>
                         <IncludeRelevanceResults>true</IncludeRelevanceResults>
                         <IncludeSpecialTermResults>true</IncludeSpecialTermResults>
                         <IncludeHighConfidenceResults>true</IncludeHighConfidenceResults>
                   </Query>
              </QueryPacket>';

         // VERY IMPORTANT - make sure the string above is actually escaped

         var soapRequest = '<?xml version="1.0" encoding="utf-8"?>
                   <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                         <soap:Body>
                               <QueryEx
                               xmlns="http://microsoft.com/webservices/OfficeServer/QueryService">
                                     <queryXml>' + userSearchQueryString + '</queryXml>
                               </QueryEx>
                         </soap:Body>
                   </soap:Envelope>';

	$.ajax({
		url: siteURL + "/_vti_bin/search.asmx",
		type: "POST",
		dataType: "xml",
		data: soapRequest,
		contentType: "text/xml; charset=\"utf-8\"",
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			ajaxError(XMLHttpRequest, textStatus, errorThrown);
		},
		success: function(xml) { processAjaxResultUserSearch(xml); }
	});
}

My problem was was that with the processAjaxResultUserSearch(xml) function, I wanted to get the person’s Title and group by that.  So I happily asked for the TITLE field (they come back as all caps for some reason), but I kept getting the preferred name!  I couldn’t figure out how to get the title from the title field.  I checked in the User Profile store, and yes, the Title field was getting populated correctly.

Well it turns out that if you go to your SSP –> Search Settings –> Metadata Property Mappings, there is a list here of a bunch of mappings such that when you search for the value on the left, you get the value on the right.  Well sure enough, next to Title, it was mapped to (among other things) People:PreferredName(Text).

So I searched around in the mappings, and I found that “JobTitle” was mapped to People:Title(Text).  I used this one, and lo and behold that’s the right one. 

IMPORTANT:  Also, make sure your Query Packet is ESCAPED, so for example

userSearchQueryString =
          '&lt;QueryPacket xmlns="urn:Microsoft.Search.Query"&gt;
                   &lt;Query&gt;
                         &lt;SupportedFormats&gt;

... etc etc

Just thought I’d pass that along.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: