Monday, June 14, 2010

Customizing People Search Results in MOSS 2007 – Part 3 of 3 – Search Results Customization

Jeremy Williams, Sr. Director, Modern Workplace

This is the third and final post of a three part series, if you missed it, here’s Part 1 and Part 2.  This post will go into the details of consuming the managed properties we configured last time around, and then displaying them in our search results.

As a review, here’s where we are:

  1. User Profile Properties Changes
  2. SharePoint Search Changes
  3. Search Results Page Customization



Add Managed Properties to List of Columns to Query

The first step to displaying your newly added managed properties in the search results is make sure they’re being returned as part of your result-set!  To do this, navigate to the people search result page on your Search site.  A quick and easy way to do this is to run a search (using the ‘People’ scope) for your own name.  Once you’re on the search page, go ahead and edit the page.  Once you have the page in edit mode, click on the context menu for ‘People Search Core Results’ and select ‘Modify Shared Web Part’.  On the pane that appears to the right, go ahead and expand the ‘Results Query Options’ Group, then click the text box under the ‘Selected Columns’ heading; and finally, click on the button with the ellipsis (…).  This will pop up a text editor.  To prevent yourself from going a little crazy, I highly recommend editing this text in something else, like Notepad/Wordpad/your favorite IDE/etc.  You will want to add a line (below) for each of your newly added custom managed properties.

<Column Name="YourManagedPropertyNameHere”/>

In the screenshot below, you can see that I’m adding my ‘StreetAddress’ managed property:


Once you’ve added all of your properties, go ahead and paste your XML  back into SharePoint pop-up text box and click ‘Ok’ on the web part property pane to save your changes.  Now, your custom property is available to and for our final step…

Reference columns in custom XSLT

Now that the people search core results web part is properly returning your managed columns, you’ll want to customize it’s XSLT (style sheet) to include the newly added column(s).  Same as last time, I highly recommend you edit this XSLT in your favorite IDE, as it’s really painful to work with code in SharePoint’s popup text-editor.  Anyways, to access the XSLT, go ahead and click ‘Modify Shared Web Part’ on the People Search Core results web part, and click the ‘XSL Editor…’ button. 

The XSLT sheet that ships with SharePoint is about 360 lines long, and there’s a couple of places you’ll need to add your column(s).  For the example, I’m simply going to stick in the ‘StreetAddress’ field after a user’s title, department, phone, and office.  Certainly, you can do much cooler things here with the XSLT, but I’ll save that for another day.  The first place you’ll need to add your column is around line 137.  In my example below, I have established my XSLT variable for StreetAddress as ‘street’ (mainly to illustrate the naming differences).

Important Note: in the ‘select’ value, be sure to use ONLY lowercase text; if you do capitalize names here, you run a very high risk of the proper field not being returned.


The next place to add the property is around line 337, as shown below:


And finally, I’ve added an XSL if-block with street around line 355:


Doing this will yield the following results:





Final Thoughts

Clearly, the trickiest part of this process is the XSLT customization, which is why I’ve chosen to show you how to simply add a property to the XSLT.  You can do all kinds of cool things with XSLT, such as return the users in a grid pattern with key information beneath their picture, or return people with a contact-card styling, the list is as long as your imagination. 

Thanks for sticking through all three posts with me; I hope this helps clear up any confusion on the whole process.


Random Error

Sometimes, SharePoint will throw a false error at you after clicking ‘Ok’ to web part changes.  The error looks something like this:


If you do come across this, simply check in your page and then click in the URL bar and press enter (don’t just refresh the page).  If you still get the error after that, you’ve most likely made a coding error in your XSLT.

Field Not Displaying

If your field isn’t returning, and you’re fairly confident that you’ve written valid XSLT and added/configured/mapped all your properties correctly, you might need to refresh your user profiles.  To do this, initiate a full import on your people profiles in SharePoint.  Once the full import has completed, start an incremental search crawl to pick up these changes.  Once complete, go ahead and run your people search again and your field should now appear:

Example of Missing Field (notice the hanging ‘-' after ‘Downtown’; this is where Street Address should be:


Example of the Missing Field existing as expected: