1

我有一个索引,有一个转换:

docs.FeedPosts
    .SelectMany(doc => (doc.Labels).DefaultIfEmpty(), (doc, docLabelsItem1) => new {AnnouncementGuid = doc.AnnouncementGuid, CreationDateUtc = doc.CreationWhenAndWhere.Time, FeedOwner = doc.FeedOwner, Key = doc.Key, Labels_Text = doc.Labels
    .Select(label => label.Text), SequentialId = ((long)doc.SequentialId), SubjectGuid = doc.SubjectGuid, SubjectId = doc.SubjectId})

(转换)

results
    .Select(doc => new {doc = doc, tags = Database.Load(doc.Key)})
    .Select(__h__TransparentIdentifier1 => new {AnnouncementGuid = __h__TransparentIdentifier1.tags.AnnouncementGuid, AreCommentsLocked = __h__TransparentIdentifier1.tags.AreCommentsLocked, Author = __h__TransparentIdentifier1.tags.Author, Comments = __h__TransparentIdentifier1.tags.Comments, CreationWhenAndWhere = __h__TransparentIdentifier1.tags.CreationWhenAndWhere, FeedOwner = __h__TransparentIdentifier1.tags.FeedOwner, Key = __h__TransparentIdentifier1.tags.Key, Labels = __h__TransparentIdentifier1.tags.Labels, MessageBody = __h__TransparentIdentifier1.tags.MessageBody, SequentialId = __h__TransparentIdentifier1.tags.SequentialId, SubjectGuid = __h__TransparentIdentifier1.tags.SubjectGuid, SubjectId = __h__TransparentIdentifier1.tags.SubjectId})

这适用于查询数据。但是,如果我随后请求统计信息,我会返回错误的文档计数!(我将查询限制为 0 个结果,并请求 raven 统计信息)。

似乎是因为我的文档看起来像这样:

{
    Labels: [
    { Text: "label 1" }
    { Text: "label 2" }
    ]
}

Raven 为这个文档生成了两个索引条目——如果我查看 raven 查询工具,第一个索引包含实际的索引数据,第二个索引文档完全是空的。

如果我在文档中有 3 个标签,它会生成 3 个索引结果……我的“计数”是应有的 3 倍。

这是怎么回事?

谢谢

4

1 回答 1

1

我将您的索引翻译为查询语法,因为这样更容易查看:

from doc in docs.FeedPosts
from NOT_USING_THIS in doc.labels
select new 
{
    AnnouncementGuid = doc.AnnouncementGuid, 
    CreationDateUtc = doc.CreationWhenAndWhere.Time, 
    FeedOwner = doc.FeedOwner, 
    Key = doc.Key, 
    Labels_Text = doc.Labels.Select(label => label.Text), 
    SequentialId = ((long)doc.SequentialId), 
    SubjectGuid = doc.SubjectGuid, 
    SubjectId = doc.SubjectId}
}

第二个 from 子句是您的索引中的 SelectMany(),您没有使用它的值如果您将其删除并在根对象之上工作,您将不会遇到此问题。

这方面的文档是: http ://ravendb.net/docs/faq/skipped-results

于 2012-07-10T08:13:51.340 回答