Adam
Adam

Reputation: 4227

Getting greater count result in raven index statistics

I have an index, with a transformation:

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})

(transform)

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})

Which works for QUERYING the data. But if I then request statistics, I get back the wrong document count! (I Limit the query to 0 results, and request raven statistics).

It seem that because my document looks like this:

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

Raven generates TWO index entries for this one document - If I look in the raven query tool, the first index contains the actual index data, the second index document is just completely empty.

If I have 3 labels in a document, it generates 3 index results... and my 'count' is 3 times what it should be.

Whats going on?

Thanks

Upvotes: 1

Views: 186

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

I translated your index to the query syntax, because that is easier to look at:

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}
}

The second from clause is the SelectMany() in your index, whose value you are not using If you'll remove that and work on top of the root object, you won't have this issue.

The docs for this are: http://ravendb.net/docs/faq/skipped-results

Upvotes: 1

Related Questions