RavenDb如何在MultiMap索引上进行实时投影?

时间:2012-01-28 19:16:54

标签: .net nosql ravendb

我有一个MultiMap索引,它有两个Map函数,用于索引两种文档类型的注释:

    public class LawDisadvantagesAndLawFixesLastCommentsIndex : AbstractMultiMapIndexCreationTask
    {
        public class IndexResult
        {
            public string Id { get; set; }
            public DateTime DateTime { get; set; }
            public string Author { get; set; }
            public string Text { get; set; }
       }

        public LawDisadvantagesAndFixesLastCommentsIndex()
        {
            AddMap<LawFix>(lawFixes => from lawFix in lawFixes
                                       from comment in lawFix.Comments
                                       select
                                           new
                                               {
                                                   Id = lawFix.Id,
                                                   DateTime = comment.DateTime,
                                                   Author = comment.Author,
                                                   Text = comment.Text
                                               });
            AddMap<LawDisadvantage>(lawDisadvantages => from lawDisadvantage in lawDisadvantages
                                                        from comment in lawDisadvantage.Comments
                                                        select new
                                                                   {
                                                                       Id = lawDisadvantage.Id,
                                                                       DateTime = comment.DateTime,
                                                                       Author = comment.Author,
                                                                       Text = comment.Text
                                                                   });
}

我真正需要的不是整个文档,而只是评论信息,因此我想将实时投影应用于此索引。但我不知道如何在MultiMap索引的情况下这样做。

1 个答案:

答案 0 :(得分:1)

只需在索引中添加以下内容:

TransformResults = (database, results) => 
    from doc in results                                
    select new
    {                                          
        DateTime = doc.DateTime,
        Author = doc.Author,
        Text = doc.Text
    };

多地图索引与常规地图索引不同。它们只是让您轻松地将索引应用于2个(或更多)文档。