Sunday, 3 August 2014

Sitecore Fast Query v/s Sitecore Query: Interesting Observation

Leave a Comment
I’ve been working with Sitecore Fast Query and Sitecore Query for a long time. Sitecore Fast Query is translated to SQL queries that be executed by the database engine. Fast Query is more efficient in terms of execution time and performance as compared to Sitecore Query. Few days ago I’ve noticed that Sitecore fast query doesn’t return hierarchical result set as compared to Sitecore content tree structure. In other words, Sitecore Fast Query retrieves a plain list of the Sitecore items regardless of the content tree hierarchy.
  • Sitecore Content Tree Structure:  Below image is part of Sitecore content tree. I’ve to find out all descendants of AccordionBottom item (item id = {2FCB17C4-8EB2-427E-97FE-12A0BECE4044}) that are based on the template with the specified Id.
  • Fast Query: Below Fast Query returns result set in jumbled order.
    fast://*[@@id = '{2FCB17C4-8EB2-427E-97FE-12A0BECE4044}']//*[@@TemplateId = '{39ACE8CB-4EE3-4989-9B73-5CAFEC21B70C}']
  • Sitecore Query: Below Sitecore Query returns result set in hierarchical order as per content tree structure.
    //*[@@id = '{2FCB17C4-8EB2-427E-97FE-12A0BECE4044}']//*[@@TemplateId = '{39ACE8CB-4EE3-4989-9B73-5CAFEC21B70C}']
Use Sitecore Query instead of Fast Query if your code logic depends on Sitecore content tree structure and you have to render the items in the same order as they are appearing in Sitecore Content tree. 
Comments and suggestions are most welcome. Happy coding! 


Post a Comment