Ok – so in Rules Queries Pt I we looked at the basic idea of Rules Based Queries for Sitecore. I followed this up with Rules Queries Pt II and we looked at how we can get results from a Rule we have defined. In both of these examples – I was mainly covering the idea behind the solution. Lets take that a little further and have a little think about WHERE we can actually use this functionality in our Sitecore sites.
For those who dont know, you can find Rules Queries for Sitecore here on Github
So I guess I will start the short version on this one is – ANYWHERE you need to get data! – but let me give you some examples 😀
The most obvious and probably the most normal use of Rules queries is as a Datasource for presentation, be that a rendering, sublayout or whatever. There is a great advantage in being able to reuse queries specified by the user in multiple area’s within your application. Just as we use datasources regularly to specify an item (and often get its child items), we can specify the rule as the datasource and get the results.
As rules are defined in Sitecore, think about the advantage (especially in locked down environments like production) of being able to fix say your new’s results page without actually having to deploy (and therefore test) a line of code!.
Using a mix of the default values (definable as child items of a Rules Query) and the API, you can use and manipulate your Rules queries to allow you to change the values in code rather than specific values defined by the user within the Rule. I call this concept – ‘System Queries’ as usually this will not be allowed for general users – it will be maintained by the developers. You can use these to drive pages like news / events / faq search functionality.
Basis of Helper Applications / Scheduled Tasks
In a similar vein to the above, you could very easily consider using the Rules queries as a basis to drive system helpers / scheduled tasks or similar within your application. Consider a products database where you need to get all items in the tree that need publishing today (without traversing the whole tree), or perhaps an import routine that needs to update a master system with the depleted stock values of all of the product variations within the system. These could easily both be driven with a rule 😀
I have found a lot of value in the Rules Queries for Sitecore development so far, as have other developers who have now leveraged it in their code. There is more functionality to come (as well as unit tests and the like). I hope above gives a little inspiration on how you might be able to solve your problems in a different manner.
In the next posts I will look at how we can extend Rules Queries to do things that are not out of the box functionality 😀 – Particularly, conditions and actions.