Tags Filtered by Container

Topics: General, Writing modules
Dec 28, 2011 at 7:20 AM

I'm looking code which filters records based on tags:

List<string> tags = new List<string> {"hello","there"};
IContentQuery<TagsPart, TagsPartRecord> query = _cms.Query<TagsPart, TagsPartRecord>();
query.Where(tpr => tpr.Tags.Any(t => tags.Contains(t.TagRecord.TagName)));

I need this code to go further: how do I make it limit the search to only those records which are in a particular Container (such posts of a particular blog)?

Dec 28, 2011 at 7:24 AM

add a join and a where.

Dec 28, 2011 at 7:32 AM

Join to a BlogPartRecord?  It doesn't have a name property. 

Dec 28, 2011 at 7:42 AM

no, container.

Dec 31, 2011 at 10:05 PM

Since I have no idea of what I'm supposed to join to, I tried adding this additional statement to the end of the prior code:

    var stuff =
        //"Primary" is the name of the blog I'm trying to limit tag results from.
        .Where(ctrPartRecord => ctrPartRecord.ContentItemRecord.ContentType.Name == "Primary")

My intent was to inspect the contents by enumerating it, but that line of code gave the following exception: 

{"could not resolve property: ContentType of: Orchard.Core.Containers.Models.ContainerPartRecord"}

What have I done wrong?

At a broader level, where do I find an ERD (aka documentation) that would enable me to answer these questions for myself?  I can't even figure how the Join<> clause knows which keys to join on (I'm guessing there is an nhibernate map that handles this behind the scenes, but I have no idea).  I'm rather familiar with EF, but have never worked with nhibernate before.  Need I learn nhibernate before writing my own Orchard module?

If nothing else, could someone tell me the specific concrete type I'm supposed to evaluate to achieve my goal?  Given the current state of Orchard documentation and code commenting - simply being advised to work with a "container" abstraction is not enough for me to extract my answer from the Orchard documentation and/or code.

Jan 6, 2012 at 5:51 AM

That looks completely different from what you said you were trying to do before. You said that you wanted posts of a particular blog. This is done with a query like:

_contentManager.Query(versionOptions, "BlogPost")
                    cr => cr.Container == blog.Record.ContentItemRecord)

(this is taken from the BlogPostService)

Now it sounds like you want all the items under all containers of a certain type?