Created
February 6, 2015 10:45
-
-
Save wictorwilen/08b4905aa8518239cacc to your computer and use it in GitHub Desktop.
Office Graph CSOM sample
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
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