Mashup Your Enterprise Search Results in SharePoint 2010 Using Refiners (and Bing Maps)

An enterprise search solution can provide you with fast and secure access to data that traditionally has been stored in different silos. This can e.g. be leveraged to create enterprise mashups, something that is particularly interesting together with information extraction techniques you'll find in more advanced search platforms like FAST Search. FAST Search for SharePoint 2010 has e.g. the ability to automatically recognize words and phrases by type (entities) within unstructured text, and for this blog post we'll look more at how we can leverage the locations extractor to create a simple mashup in your search results page. The locations extractor will tag each document with extracted locations (during document processing), and we'll use the Bing Maps AJAX API to geo code these locations before we plot them on a map on the search results page. Note that the locations are available in a locations refiner, and will reflect your entire search results when using FAST Search (as a "deep" refiner, see e.g. here for more on refiners - aka faceted search).

Background

To mashup your location refiner with a Bing Map we can e.g. implement a new Web Part. The approach we are taking here is very similar to what was shown in order to create a Tag Cloud and a Bar Chart Web Part, i.e. plug in a new Web Part that will work with and leverage existing search Web Parts in a search center. Use the RefinementManager to fetch the refinement results for the locations refiner, and use the Bing Maps API to geocode and plot the locations on a map. Note that the Bing Maps AJAX API is based on client side JavaScript, so we need some plumbing to load the JavaScript in the Web Part (as Web Parts are running serverside).

The screen shot below is from a FAST Search results page with a Bing Maps Mashup Web Part added.

 

Setup

The locations refiner is available out-of-the-box from FAST Search. It is however not configured to be fetched and displayed in the Refinement Panel Web Part by default, so we need to specify this first;

  • In your FAST Search Center, click Site Actions > Edit Page
  • Edit your Refinement Panel Web Part;
    • Update the Filter Category Definition XML, and add an entry to include the locations managed property
      • <Category Title="Location" Description="Locations found in document" Type="Microsoft.Office.Server.Search.WebControls.ManagedPropertyFilterGenerator"    MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" ShowMoreLink="True" MappedProperty="locations" MoreLinkText="show more"    LessLinkText="show fewer" ShowCounts="Count" />
    • Uncheck Use Default Configuration, and Click Apply
    • Click Save to go back to your search page

See also previous blog entry for instructions on how to setup your Visual Studio environment.

Implementation

I've attaced some sample code to this blog post (see link below), i.e. an implementation of a Web Part called BingMashupWebPart (note that code is for illustration purposes, not meant to be ready for any production system). In the BingMashupWebPart.cs class, the method CreateChildControls()  outputs a div tag for the JavaScript to be able to render the map. The OnPreRender() method contains most of the logic; it fetches any refinement results using the RefinementManager and an XPath expression, then formats the refinement values as JavaScript string. The dynamically generated JavaScript (based on refinement values) is registered on the ClientScriptManager on the Page, and so is the BingMashupScripts.js file. Quick note: to refer the JavaScript file from the Web Part you can set the Build Action property to Embedded Resource for the file.

The JavaScript file contains the functions needed to geocode each location, plot the locations on a map together with an information box, scale the map to fit all locations, and place the map on the div we added in the Web Part (see e.g. Getting a Precise Location in Bing Maps for more details on geo coding and the Bing API). Note that the Refinement Manager is shared on a page, and if we cannot assume that the Refinement Panel Web Part will be available, we must set which refiners to fetch ourselves in code. Alternatively we can extend the RefinementWebPart class. Note also that the locations refiner is configured to return the 20 most important locations for your search results in the XML above (see setup section).

Test

See previous post on how to add the Web Part to your search page.

Summary

With FAST Search for SharePoint 2010 it is easy to hook into your search results and create new and interestring mashups. This blog post has shown how to mashup values from the locations refiner with Bing Maps, but the options are many. Other "deep" refiners are e.g. companies and person names, in addition to of course the search results them selves. 

BingMashup.zip

Comments

  • Anonymous
    March 08, 2011
    Hi, great article. Question, how are custom "deep" refiners created, say e.g. you want to refine by document size (I'm not sure if that's a refiner already available, but you might get the drift of the question)