Sitecore Query Parsing Tree

Yesterday, I had a college about Design Patterns. This can be  very interested, but it requires a teacher which can describe the problems in a good way and show unlimited examples. To bad, the theacher wasn’t able.
So I decided to show some of the stuff in Sitecore(Factories, Facades, etc) to one my my classmates. And while clicking trough my Sandcastle -dump of Sitecore 5.3, I run trough the Query-class(Sitecore.Data.Query.Query). I knew that Sitecore uses lexical analysis, but what I didn’t knew was, that they provide the parsing-tree :).  For example, add the following code to the ‘Sample layout.aspx’:

<script runat=”server”>
protected override void Render(HtmlTextWriter output)
Sitecore.Data.Query.Query myQuery = new Sitecore.Data.Query.Query(“/sitecore/*[(@name=’content’ or @name=’master’)]/*[@@fieldname < 11]”);

This is what appears on the screen:

– Root
– Children [“sitecore”]
– Children [“*”]
   – Predicate
      – OrOperator
         – EqualsOperator
            – FieldElement [“name”]
            – Literal [“content”]
         – EqualsOperator
            – FieldElement [“name”]
            – Literal [“master”]
– Children [“*”]
   – Predicate
      – SmallerOperator
         – FieldElement [“@fieldname”]
         – Number [“11”]

So now it’s possible to optimize your queries as you are now able to minimalize it’s states :).