Welcome back! This post will be the conclusion of my Search Federation article. In Part 1, I talked about Federation in Microsoft Office SharePoint Server (MOSS) and Microsoft Search Server (MSS/X), and showed you how to create a basic Federated Location to query an external resource - in this case, Twitter.
While that Location definition is functional, it doesn't really bring the "feeling" of Twitter into your SharePoint search. Sometimes, that may be exactly what you need. However, today, I'm going show you how to take it to the next level by using SharePoint Designer.
This post assumes you have already read Part 1, and have access to the Federated Location created there. You can either follow the instructions in Part 1 now, or download and install the Location from here.
A Starting Point
I'm going to use the basic Twitter Federated Location I created in Part 1 as the starting point for our prettier, deluxe version. To start, Go into Central Administration, and navigate to the Manage Federated Locations page. Find the Basic Twitter Results location, and select Copy Location from the drop-down menu.
All of the settings we created for that location will now be pre-fed into a new location definition, except for the Location Name. We're going to call this location "TwitterDeluxe", and change the display name to Enhanced Twitter Results. Otherwise, leave everything the same for now, and click "OK".
Once you have saved the Location, it will appear in the list along with all of the others.
Exploring the Source
In order to see just what we can do with our Location, we need to know what is "in" it. The key component is the Query Template, where we told Search Federation what to query. Let's review the Query Template for our Federated Location.
Go back into the properties by selecting "Edit Location" from the item's menu. Once the editing page opens scroll down to the Location Information section, and expand it. You will see the query defined by Twitter:
http://search.twitter.com/search.atom?q={searchTerms}
To generate some example data, I'm going to replace the {searchTems} token with an actual value - "SharePoint"
http://search.twitter.com/search.atom?q=sharepoint
Clicking this link will call the Twitter search service, and return an Atom feed of the results:
Notice that there is much more information showing than we saw in our Federated Location result set, including such information as the Tweet's author, and the date/time stamp. So, how do you get to this in the Federated Location?
In Part 1, even though we didn't change it from its default values, I told you that the Display Information section of the Location definition was going to play an important role in this Part. Now's the time. In the Edit Location page, scroll down to the Display Information section and expand it. I'm only concerned about the first block: Federated Search Results Display Metadata.
Notice there are three properties here:
- XSL
- Properties
- Sample Data
All of these properties are nice XML and XSL files. Personally, I'm not a big fan of manually editing XML and XSL. Fortunately, we have a wonderful tool designed just for editing such data - SharePoint Designer. in a perfect world, we could just add a Federated Results component to a page, assign the appropriate Federated Location, open the page in SharePoint Designer, and edit it to our heart's desire.
Unfortunately, we don't live in a perfect world. Yes, we can open the page in SharePoint Designer, and edit the part. But no, we don't have access to "The Full Monte". It starts out promising. We can uncheck "Use Default Formatting", view the source from our RSS results, and paste that into the Sample Data field. When we save the Location, assign it to a Federated Results Web Part, and open the results page in SharePoint Designer, we can see the sample data:
We can even change the format of the existing columns. But, although SharePoint Designer recognizes the Federated Results as a form of Data View, it doesn't give us full access to the Data View editing features. We can't easily get to the rest of the information we know is coming from the feed. Since Federated Search arrived much later than SharePoint Designer, I can't really fault SPD for not fully supporting the web part, but I hope that gets resolved in a future update.
You might think that this leaves us at an impasse. But it doesn't. Because, while SPD doesn't give us full Data View support on the Federated Results web part, we do have another way to edit XSL - the original Data View/Data Form Web Part!
A Data View Refresher
The Data View Web Part is a way to display information from virtually any source within SharePoint. Data Views are created in SharePoint Designer, in association with another feature called the Data Source Library. This is not to be confused with the "Business Data Catalog", or BDC. While both the Data Source Library and the BDC deal with presenting data from external sources within SharePoint, the BDC is a part of MOSS Enterprise, and allows a much deeper integration of the data with various aspects of SharePoint. The Data Source Library, on the other hand, is available in all editions of SharePoint - from WSS on up - and is primarily used to generate Data View/Data Form Web Parts.
Data Views and the Data Source Library are a very powerful combination - so much so that almost two whole chapters of my book are devoted to them. Obviously, I can't go into that kind of detail here, but while this particular example is fairly simple, it covers a lot of ground.
The link between Federation and Data Views is pretty close. In fact, prior to Search Server or the Infrastructure Updates, you could use a Data View to achieve very similar results. We're going to take advantage of this by building the look we want in a Data View, then transferring it into the Federated Location definition.
Creating a Data View
Before we can create a Data View, we need create a new item in the Data Source Library for our Atom feed.
To do this, Select "Manage Data Sources..." from the Data View menu in SharePoint Designer to summon the Data Source Library task pane. Atom and RSS feeds fall into the category of "Server-side Scripts" that return XML, so expand the Server-side Scripts section and click "Connect to a script or RSS Feed." You will see the dialog below. Fill in the URL with the same Twitter Atom query we have been using:
The query parameter (q) will automatically be passed into the list as soon as you change the focus from the URL field. "SharePoint" will become the default parameter value, and give us something to see as we customize the look.
Now that we have the Data Source, we need a place to put it. This can be any web part page. While you can use the results page if you feel so inclined, because we aren't going to be using the Data View directly, it doesn't need to be.
Once you have a web part page open, select a Web Part Zone, and then pick "Insert Data View..." from the Data View menu. The Data Source you created above will have a drop-down menu associated with it. Select "Show Data".
You will see the Data Source Details task pane, with the structure of the Twitter Atom feed displayed.
I've maximized my task pane for this screen shot in order to show you how the SharePoint Designer data source displays the entire structure of the feed. Notice the folders and item scrolls for the various elements. The Twitter Atom feed is a "hierarchical" data source. This means that the data has nested, potentially (and in this case, actually) repeating, elements, which in turn may have their own nested elements.
For now, the primary entity we are interested in is the "Entry" folder. Look at the screen shot to the right. Highlight the elements in the "Entry" folder as shown, and select "Multiple Item View" from the "Insert Selected Fields as..." menu. (Yes, I know. It looks like a button, but trust me - it's a menu!)
A table will be inserted into the web part. That's got most of the information we want, but it isn't terribly pretty. So, let's fix it up!
The first column contains the "href" entity. Ironically, even though there is a separate entity for the Author, one of the two links listed for each user is the Author's avatar. The other is a link to the Twitter URL of the tweet itself. For our results, we really only want the avatar, so we're going to do two things - Change the display to show the image instead of the URL, and hide the other URL.
To change to an image view, click one of the URLs in the href column. To the right will be a little box with a chevron in it:
When you click it, you will have choices to modify the current field. Select Picture.
You will get a warning that URLs and Pictures can be dangerous. We know that, so click Yes.
The changes you make here will affect all of the items of that series. (You probably noticed that they were all highlighted in a different color when you clicked on any one of them.)
Once you have done that, to suppress the other image (which will show as a "broken" picture), Right-click the broken link and select "Conditional Formatting". In the Conditional Formatting task pane, select "Show Content" from the "Create" menu (another one of those "buttony" menus). In the Condition Criteria box, set the conditions like this:
The broken link will go away.
Next, we want to merge the rest of the cells in the row. This is just like any other table action - highlight the data cells (not the labels) for content, updated, name, and uri. Right-click, and select "Modify/Merge Cells". Now we're cooking! Just a couple more tweaks, and it will be there.
Select the tweet content text, and change its format to Rich Text (just like changing the image format above).
Select the date, and format it to your regional liking.
Notice that we have a link to the Author, the Author's name, and the Author's avatar. Wouldn't it be great to have the name and the avatar actually link to the Author's page? Well, we can. If you click the chevron by the link, you will see that the field being displayed is called "ddw1:author/ddw1:uri". For the text, change the format to Hyperlink, you will see the following dialog. You can use the "fx" icons to select the fields you wish to use in the hyperlink, or enter the values manually. In either case, you want the "Text to display" and "Address" fields to be set as shown:
Setting the link on the picture is easy, too. Just right-click the image, and select "Hyperlink" from the context menu. Set the address to the same token as you used above. Now you can delete the field that shows the text of the author link.
You should now have a web part that looks a lot more like what you would expect from a Twitter search:
Pretty good, but I'm still not satisfied. :)
Notice the Chevron icon in the upper-right corner of the web part.
If you click it, you will summon the "Common Data View Tasks" menu:

Click Data View Properties. You will get this dialog:
Click "Show view header" and "Show view footer", then click the "Paging" tab.
Click "Limit the total number of items displayed to:" and enter a reasonable number for a search results page. (I picked 5). (You need to do this because the XSL we are creating will not have a link to the Federated Location web part's "Results per page" property.) Click OK.
Display the Data Source Details task pane, and drag the first title field available into the newly created header. Click in the footer, and delete the Item Count. In the "link" group (above the "title" field you just used), make sure item 1 (rel = "alternate") is selected. Highlight the "href" and select "Item(s)" from the Insert Selected Field menu. Change its format to a Hyperlink. Leave the Address as-is, but change the Text to Display to "More Results..."
I'm going to delete the field name row, rearrange the fields slightly, and also apply the style "ms-searchChannelTitle" to the Header cell. This results in a part that looks like this:
Moving the XSL
Now that we have something that looks how we want it, how do I get this style into my federated location? If you don't like code, this is going to get a bit messy, because now we need to enter "Split" view in SharePoint designer. Essentially, we need to copy the XSL markup from this web part. To do this, click the "Split" view icon at the bottom of the SharePoint Designer design surface workspace window, then click the title bar of your web part. This will highlight the code that makes up the web part. Using the scroll bar, Scroll through the highlighted code area until you you find the <Xsl> tag. It will be followed by lots of code. You want to copy everything below the <Xsl> tag until you find the closing </Xsl> tag to the clipboard. (Do not include <Xsl></Xsl> themselves.)
Now, go back to your "TwitterDeluxe" Federated Location definition in Central Administration. Go to the "Display Information" section, and replace the contents of the "XSL:" field in the Federated Search Results Display Metadata with the code you just copied. Click OK to save the changes.
The Net Result
Now you can go to your results page, and assign your Enhance Twitter Results location definition to your Federated Results web part. Here's what it looks like in action:

Now, this was a lot of steps. In reality, it is a lot faster to do than to describe. However, as promised, I am making this location available for you to download.
Click this link to download the Federated Location definition file.
I hope you have enjoyed this article!