获得更多计数会导致乌鸦索引统计数据

时间:2012-07-10 04:10:18

标签: ravendb

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

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结果,并请求乌鸦统计数据。)

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

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

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

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

怎么回事?

由于

1 个答案:

答案 0 :(得分: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