.net - RavenDb MapReduce index with three from cases in Map -
.net - RavenDb MapReduce index with three from cases in Map -
i have next post entity:
public class post { public string id {get;set;} public string text {get;set;} public ilist<vote> votes {get;set;} public ilist<comment> comments {get;set;} }
for list of posts need retrieve id, text, rating (sum of votes), commentscount. tried create next mapreduce index:
public class postsforlist: abstractindexcreationtask<post, postsforlist.reduceresult> { public class reduceresult { public string id { get; set; } public string text { get; set; } public long rating { get; set; } public long commentscount { get; set; } } public postsforlist() { map = posts => post in posts comment in post.comments vote in post.votes select new { id = post.id, text = post.text, rating = vote.value /* 1 or -1 */ commentscount = 1, }; cut down = results => result in results grouping result result.id grouped select new { id = grouped.key, text = grouped.select(x => x.text).first(), rating = grouped.sum(x => x.rating) commentscount = grouped.sum(x => x.rating), }; } }
it looked reasonable me initially. looks map 3 clauses won't work. other solution see utilize multimap index 2 maps (one votes , 1 comments). looks bit unusual utilize multimap index both indexes query same document... there other solutions?
idsa, there's no need define index here. both collections, votes
, comments
part of document, utilize them:
var posts = documentsession.query<post>() .skip(currentpage*pagesize) .take(pagesize) .tolist(); // here db-call! next in-memory var viewmodelposts = post in posts select new { post.id, post.text, rating = post.votes.sum(x => x.value), commentscount = post.comments.count };
update: really want precompute results, take here: http://daniellang.net/using-an-index-as-a-materialized-view-in-ravendb/
.net nosql ravendb
Comments
Post a Comment