2

I have a Sitecore data template called "Meeting". It has a field called "Additional Activities". This field is a multi-list that allows the content editor to associate many different Activities with a meeting. My Meeting content items do not all live in the same folder in the content tree. They are spread out throughout the site. Given a particular Activity, I need to be able to find and display a list of all of the associated Meetings for that Activity. Right now I am using Sitecore Query as follows:

/Sitecore/Content/Home//*[(@@templatename='Meeting') and (contains (@@#Additional Activities#, '{C73FAE38-DBF5-42C9-B872-8E412B99E9DE}'))]

That works, but it is terribly slow. I thought about creating some sort of in-memory cache that I could query, but then I have problems with when to rebuild the cache. I also thought of using Lucene, but I have found Lucene queries to be super complicated to implement. Does anyone have any suggestions as to a better way to do this? Should I just use Sitecore Query to get the list of ALL Meetings in the content tree and then iterate through them?

3 Answers 3

3

There is an alternative to Lucene, to what you are trying to do. Let me be clear though; I agree with Klaus, looking into Lucene is the recommended route. That being said; here's an alternative version. For what you are trying to do, you can use the Sitecore LinkDatabase. It will do the trick for you, as long as you are only looking to find meetings that reference a particular activity.

The code would look something like this:

       Item activityTemplate = Sitecore.Context.Database.GetItem( "/sitecore/templates/path/to/your/activity/template" );
        var links = new List<ItemLink>( Globals.LinkDatabase.GetItemReferrers( activityTemplate, false ) );
        List<ItemLink> filteredLinks = links.FindAll( il => il.SourceDatabaseName == Sitecore.Context.Database.Name );

        // filtered links is now a list of all references to your activity
        foreach ( ItemLink fl in filteredLinks )
        {
            Item si = fl.GetSourceItem();

            // Check if the reference is a meeting item
            if ( si.TemplateID == Sitecore.Data.ID.Parse( "{0E06BFCA-3595-4F31-BDBF-746EE6663B4A}" ) && si.Paths.FullPath.StartsWith( "/sitecore/content" ) )
            {
                // si is your meeting item
                Response.Write( si.Paths.FullPath + "<br />" );
            }
        }

Execution time for this query is as fast (possibly slightly faster) than the Lucene equivalent, and most definitely faster than your raw Sitecore Query.

1

Lucene query withan indexof all you meeting items is the way to go.

Will be really fast. Are you on Sitecore 7 or 6? i guess the tag says 6 so use the advanced database crawler from marketplace to set up the index and the query should be pretty straight forward.

2
  • Agree. Advanced Database Crawler reduces the complexity of Lucene considerably Jan 8, 2014 at 23:59
  • I tried getting started with Advanced Database Crawler once. I couldn't understand at all how to use it. I found the documentation to be lacking and confusing. Jan 9, 2014 at 0:42
1

Depending on your Sitecore version, you can also use the Fast query:

query:fast:/Sitecore/Content/Home//*[@@templatename='Meeting' 
       and @@#Additional Activities#='%{C73FAE38-DBF5-42C9-B872-8E412B99E9DE}%'] 
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.