Ravendb实时预测产生空值(Ravendb Lucene,Multimap,实时预测)

时间:2012-10-30 01:08:13

标签: lucene ravendb multimap

首先,我很抱歉我的英语,如果我能非常简单地讲述我的问题,我将非常高兴。

我花了很多时间来解决多图索引和实时投影问题。我在stackoverflow,google,ayende博客等上读了太多...但是无法解决我的问题。

我想要的是什么:    我有一个应用程序,想要一个像搜索一样的Twitter,这是Twitter搜索框从多个来源搜索,例如来自twit内容,用户名和主题标签。当我得到结果时,我想将结果转换和形状索引结果应用到FullSearchResult模型中。我也想找到结果的位置。在帖子中,在用户中还是在标签中?

问题:    我有3种类型的文档(帖子,用户,标签)和多图索引。当我使用TransformResults创建我的多图索引时,我得到的所有结果都是空值。 (我通过全文搜索查询带有多图索引的文档)。

我的文档

public class Post
{
    public string Id { get; set; }

    public long SqlDbId { get; set; }

    public string Title { get; set; }

    public string Content { get; set; }

    public string ContentAsHtml { get; set; }

    public Status Status { get; set; }

    public DenormalizedUser User { get; set; }

    public DenormalizedTagCollection Tags { get; set; }
}

public class User
{
    public string Id { get; set; }

    public string Name { get; set; }

    public string Surname { get; set; }

    public string Email { get; set; }

    public string MobileNumber { get; set; }
}

public class Tag
{
    public string Id { get; set; }

    public long SqlDbId { get; set; }

    public string TagName { get; set; }

    public DenormalizedUser TagInserterDenormalizedUser { get; set; }

    public bool IsSystemTag { get; set; }

    public Status Status { get; set; }
}

public class FullSearchIndex : AbstractMultiMapIndexCreationTask<FullSearchResult>
{
    public FullSearchIndex()
    {
        AddMap<Post>(posts => from post in posts
                              let tags = post.Tags
                              where post.Status == Status.Active
                              select new
                              {
                                  UserId = post.User != null ? post.User.Id.ToString() : (string)null,
                                  PostId = post.Id,
                                  TagIds = tags != null ? tags.Select(tag => tag.Id).ToArray() : new string[0],
                                  SearchQuery = new object[] 
                                  {                                      
                                      post.Title,
                                      post.Content,
                                      post.Tags != null ? tags.Select(x => x.TagName).ToArray() : new string[0]
                                  },
                                  Source = SearchResultSource.ResultIsFromPost
                              });

        AddMap<User>(users => from user in users
                              select new
                              {
                                  UserId = user.Id,
                                  PostId = (string)null,
                                  TagIds = new string[0],
                                  SearchQuery = new object[] 
                                  {                                      
                                      user.Name,
                                      user.Surname
                                  },
                                  Source = SearchResultSource.ResultIsFromUser
                              });

        AddMap<Tag>(tags => from tag in tags
                            where tag.Status == Status.Active
                            select new
                            {
                                UserId = (string)null,
                                PostId = (string)null,
                                TagIds = new string[] { tag.Id },
                                SearchQuery = new object[] 
                                {
                                    tag.TagName
                                },
                                Source = SearchResultSource.ResultIsFromTag
                            });

        Index(searchResult => searchResult.SearchQuery, FieldIndexing.Analyzed);

        TransformResults = (clientSideDatabase, results) =>
                                from result in results
                                let post = clientSideDatabase.Load<Post>(result.PostId)
                                let tags = clientSideDatabase.Load<Tag>(result.TagIds)
                                let user = clientSideDatabase.Load<User>(result.UserId)
                                select new
                                {
                                    PostId = post != null ? post.Id : (string)null,
                                    PostTitle = post != null ? post.Title : (string)null,
                                    PostContent = post != null ? post.Content : (string)null,
                                    PostTags = tags != null ? tags.Select(x => x.TagName).ToArray() : (string[])null,

                                    UserId = user != null ? user.Id : (string)null,
                                    UserName = user != null ? user.Name : (string)null,
                                    UserSurname = user != null ? user.Surname : (string)null,
                                    UserEmail = user != null ? user.Email : (string)null,
                                    UserMobileNumber = user != null ? user.MobileNumber : (string)null
                                };
    }
}

当我使用multimap索引和lucene搜索查询时,我有4个结果。但是,所有值都为空

query = "Tag50";
session.Query<FullSearchResult, FullSearchIndex>()
                        .Search(resultItem => resultItem.SearchQuery, query)
                        .As<FullSearchResultViewModel>()
                        .ToList();

1 个答案:

答案 0 :(得分:0)

Nkaya, 您假设TransformResults的输入是地图的输出,但事实并非如此。 TransformResults的输入是实际的文档。地图的输出用于生成搜索索引,而不是形成转换结果的输入结果。