Developing Apps against the Office Graph - Part 1
http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2014/09/15/developing-apps-against-the-office-graph.aspx
Developing Apps against the Office Graph – Part 2
http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2014/09/17/developing-apps-against-the-office-graph-part-2.aspx
Using Graph Query Language (GQL) with the SharePoint Online Search REST API to query Office graph:
http://msdn.microsoft.com/en-us/library/office/dn783218(v=office.15).aspx
So basically we can say that the Graph Query Language can be used to filter normal search queries to return content which is highly relevant to the user. I think the most important thing about the GQL is the EdgeWeight property which can be used to return content sorted by it's "closeness" to the user. This 'magic' property will also return a relevance score of how close the object (content) is to the actor (user).
For example, if I make a query to get all the people with whom the current user closely works with, the person who will have the highest relevance score will be the person with whom the current user works with most closely. The next person will have a slightly lesser relevance score and so on. This will also be true for other queries such as documents which are most relevant to the current user. This data can be very useful and can be used in a variety of scenarios.
Here is an example of a query to get the users with whom the current user works closely. I have modified the code from Richard diZerega's blog which is linked above.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function ($) { | |
$(document).ready(loadEverything); | |
function loadEverything() { | |
var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?Querytext='*'" + | |
"&Properties='GraphQuery:ACTOR(ME\\, action\\:1019),GraphRankingModel:{\"features\"\\:[{\"function\"\\:\"EdgeWeight\"}]}'"+ | |
"&RankingModelId='0c77ded8-c3ef-466d-929d-905670ea1d72'"+ | |
"&SelectProperties='Title,UserName,Path'" + | |
"&RowLimit=10"; | |
$.ajax({ | |
url: queryUrl, | |
method: "GET", | |
headers: { "Accept": "application/json; odata=nometadata" }, | |
success: function (data) { | |
var results = []; | |
$(data.PrimaryQueryResult.RelevantResults.Table.Rows).each(function (i, e) { | |
var o = {}; | |
$(e.Cells).each(function (ii, ee) { | |
if (ee.Key == 'Title') | |
o.title = ee.Value; | |
else if (ee.Key == 'UserName') | |
o.username = ee.Value; | |
else if (ee.Key == 'Path') | |
o.path = ee.Value; | |
}); | |
o.pic = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/userphoto.aspx?size=m&accountname=' + o.username; | |
results.push(o); | |
}) | |
RenderEverything(results); | |
}, | |
error: function (jqXHR, textStatus, errorThrown) { | |
console.log(textStatus + " : " + errorThrown); | |
} | |
}); | |
} | |
function RenderEverything(results) { | |
var previewsContainer = $("#OGPreviews"); | |
$(results).each(function (i, e) { | |
var theImg = $("<a href='"+ e.path +"'><img src=" + e.pic + " title='"+ e.title +"'></img></a>"); | |
previewsContainer.append(theImg); | |
}) | |
} | |
})(jQuery); |