Using Faceted Search from the LinkedIn API

As many of you know, I’m now happily employed as a Developer Advocate at LinkedIn. Part of my job there is to create interesting examples using our APIs, to help other developers find their footing and create new and interesting applications.  This will be the first in a long line of posts demonstrating how to use our API to create cool apps.

Note that this, as with many other applications, will be much less interesting with small networks. Grab more connections and it’ll have more cool data to play with.

My passion has always been for showing interesting intersections of data.  The LinkedIn website has a faceted search feature you can see when browsing people you may know. On the left hand side of that page, you’ll see companies and schools listed there.  Selecting one or more companies restricts the people to those folks who match one of those companies.  Selecting a school or schools does the same thing.  Selecting both creates an “and”.

Try these examples on the website to get a feel for how the facet searches work. Because these facets are tuned to your network, you’ll have different companies and schools, but you can still see how the intersections work.

  • People who worked at Netflix in the past
  • People who worked at Netflix in the past *and* attended Stanford University
  • People who worked at Intel in the past and work at Yahoo! now
  • People who worked at either Cisco Systems or Microsoft in the Past

This same functionality is available via the LinkedIn API. Information on faceted search can be found in the People Search API documentation.

FacetBrowse

So how does this translate into a real application? The application above shows one possible implementation. But how does it work?  I’ll walk through the pieces of this application.  If you want to see the source application (which uses the LinkedIn JSAPI for interaction with LinkedIn, and YUI for presentation) you can look at the page directly at http://www.princesspolymath.com/facetbrowsesmall.html

On the left hand side of the application you see a list of buttons – by default you’re looking at the companies, but go ahead and switch to schools. This list is built as soon as the user has authenticated with LinkedIn, with a raw query to the API:

function onLinkedInAuth() {
    IN.API.Raw("/people-search:" +
   "(people:(first-name,last-name,positions:" +
    "(company:(ticker,name)),educations,picture-url),facets:" +
    "(code,buckets:(name,code,count)))?" +
    "facets=current-company,school&sort=distance&count=25")
    .result(displayFacetResults)
}
</blockquote>

</pre> > > This returns the top 10 schools in your network, the top 10 companies in your network, and 25 of your contacts. FacetBrowse builds the buttons for the left hand side of the widget and labels them so the app knows what’s been selected when someone clicks one of the buttons. It then trims out contacts who don’t match any of the top companies or schools, leaving you with something that looks like this: > > > > Any time one of the buttons is clicked, the function refreshConnections is called, which does the same facet search – this time specifying a company and/or school. > > > <pre>function onLinkedInAuth() { IN.API.Raw(“/people-search:” + “(people:(first-name,last-name,positions:” + “(company:(ticker,name)),educations,picture-url),facets:” + “(code,buckets:(name,code,count)))?” + “facets=current-company,school&sort=distance&count=25” + “facet=past-company,{company-code}&facet=school,{school-code}) .result(displayFacetResults) }</pre> > > Note that because of the way the facet search works, you can’t create intersections within the request (this company *and* that company). Since I want to create these intersections, when I’m refreshing connections, I ask for one of the companies and one of the companies and then eliminate matches which don’t match all of the company/school choices. > > For instance, when the user selects two different companies, such as they have here:

The application asks for the people-search and declares “current-company=“. When the results come back, each person is inspected to make sure that they have both Microsoft and Netflix within their positions. Matching results are displayed in the grid.

If a school is then selected (so now we have Stanford, Microsoft and Netflix):

The query requests Stanford University as a school and Microsoft as a company, and then checks each returned person to make sure they also have Netflix in their profile.

This application is just a small example of what can be done with the LinkedIn faceted search. Tell me in the comments if you’ve found other uses for it, or have questions about how it works.

Dialogue & Discussion