我有以下文件:
public class Post
{
public string Id {get;set;}
public string BlogId {get;set;}
public string AuthorId {get;set;}
public string Content {get;set;}
}
public class Blog
{
public string Id {get;set;}
public string Language {get;set;}
}
我需要创建一个索引,以便我可以用特定语言计算博客中每个用户的帖子数(所以我想过滤Blog.Language属性)。
首先我认为multimap / reduce索引是一种方法:
AddMap<Post>((posts) => from post in posts
select new
{
UserId = post.AuthorId,
Count = 1,
Language = Language.None
});
AddMap<Blog>((blogs) => from blog in blogs
select new
{
UserId = null,
Count = 0,
Language = blog.Language
});
但是你看到Blog中没有指定UserId属性,所以我认为我不能让Reduce部分工作(因为我要减少UserId属性)。
答案 0 :(得分:1)
据我了解,您不需要索引中的博客,而是他们的语言:
AddMap<Post>((posts) => from post in posts
select new
{
UserId = post.AuthorId,
Count = 1,
Language = LoadDocument<Blog>(post.BlogId).Language
});
然后按UserId
和Language
缩小:
Reduce = results => from result in results
group result by new { result.UserId, result.Language }
into g
select new {
UserId = g.Key.UserId,
Count = g.Sum(x => x.Count),
Language = g.Key.Language
};