Skip to content

Instantly share code, notes, and snippets.

@wictorwilen
Created February 6, 2015 10:45
Show Gist options
  • Save wictorwilen/08b4905aa8518239cacc to your computer and use it in GitHub Desktop.
Save wictorwilen/08b4905aa8518239cacc to your computer and use it in GitHub Desktop.
Office Graph CSOM sample
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
List<OfficeGraphResult> graphResult = new List<OfficeGraphResult>();
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
var keywordQuery = new KeywordQuery(clientContext)
{
QueryText ="*",
RowLimit = 10
};
var gql = new QueryPropertyValue()
{
StrVal = "ACTOR(ME, action:1003)",
QueryPropertyValueTypeIndex = 1
};
keywordQuery.Properties.SetQueryPropertyValue("GraphQuery", gql);
var rank = new QueryPropertyValue()
{
StrVal = @"{""features"":[{""function"":""EdgeTime""}]}",
QueryPropertyValueTypeIndex = 1
};
keywordQuery.Properties.SetQueryPropertyValue("GraphRankingModel", rank);
keywordQuery.RankingModelId = "0c77ded8-c3ef-466d-929d-905670ea1d72"; // Important since we specify the Graphrankingmodel
var searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();
var relevantresults = results.Value.FirstOrDefault(t => t.TableType == "RelevantResults");
if (relevantresults != null)
{
relevantresults.ResultRows.ToList().ForEach(rr =>
{
var r = new OfficeGraphResult();
r.Title = rr["Title"] as string;
graphResult.Add(r);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment