I was looking at the source code for RacoonBlog trying to find a way in RavenDB to query on a collection contained in a document. I did read about indexes and Map / Reduce and failed to find my answer.
In the PostsController there is an ActionResult called Tag that takes a string parameter and contains the following linq query.
var posts = RavenSession.Query<Post>()
.Include(x => x.AuthorId)
.Statistics(out stats)
.WhereIsPublicPost()
.Where(post => post.TagsAsSlugs.Any(postTag => postTag == slug))
.OrderByDescending(post => post.PublishAt)
.Paging(CurrentPage, DefaultPage, PageSize)
.ToList();
The Where extension method calls TagsAsSlugs and performs an Any, TagsAsSlugs looks like this.
public IEnumerable<string> TagsAsSlugs
{
get
{
if (Tags == null)
yield break;
foreach (var tag in Tags)
{
yield return SlugConverter.TitleToSlug(tag);
}
}
}
So since the TagsAsSlugs property loops over the collection of tags does the query require that all posts are returned so that each post can have its Tags collection iterated over?
I doubt this is the case since Oren's blog is so fast.
Jackson, No, that is NOT how it works. We are doing the work during indexing (the TagsAsSlugs is actually computed on save time), and then we save TagsAsSlugs into the index. We query the index for tags that exists there.
In short, we don't do any computation, certainly not on the client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With