RavenDB:排序、索引和投影
假设我有一个如下所示的模型:
public class Blog
{
public string BlogId { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
}
public class Post
{
public string PostId { get; set; }
public string BlogId { get; set; }
public string Text { get; set; }
}
我有很多博客,每个博客都有很多帖子。现在我想要一个像这样的“博客摘要视图”:
public class BlogSummaryView
{
public string Id { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
public int PostCount { get; set; }
}
如果我希望能够对创建日期和帖子数量<进行排序,我应该如何获取此列表/em>?
我可以添加一个映射/归约索引来获取每个博客的帖子数量并对其进行排序,但我无法使用此索引对博客创建日期进行排序。
添加地图索引使我可以按创建日期排序。不过,这个索引不允许我对帖子数量进行排序,除非我遗漏了一些东西。
Let's say I have a model that looks like this:
public class Blog
{
public string BlogId { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
}
public class Post
{
public string PostId { get; set; }
public string BlogId { get; set; }
public string Text { get; set; }
}
I have many blogs, each with many posts. Now I want a "blog summary view" like this:
public class BlogSummaryView
{
public string Id { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
public int PostCount { get; set; }
}
How should I go about to get this list if I want to be able to sort both on the creation date and the number of posts?
I can add a map/reduce index to get the number of posts per blog and sort on it, but I would not be able to sort on blog creation date with this index.
Adding a map index gives me the possibility to sort by creation date. This index would not allow me to sort on number of posts though, unless there is something I'm missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
克里斯托弗,
这就是为什么我们有多映射归约索引。看:
http://ayende.com/blog/89089/ravendb-multi-maps -减少索引
Kristoffer,
That is why we have multi map reduce indexes. See:
http://ayende.com/blog/89089/ravendb-multi-maps-reduce-indexes