Following on from my previous post on Creating Custom Permissions in Sitecore. I thought I would expand this to show a typical use case a little more. More than once I have had the requirement to show ‘non-logged-in’ users an alternative version of a page (think experts exchange where you have to sign in to see the answer to a question). This by default in Sitecore is not so tricky, but you cannot simply do it by preventing read permissions to an item.
I have chosen to base this functionality on Conditional Renderings as, in Sitecore’s out of the box functionality, it already allows us to hide / change the datasource of pieces of presentation.
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
Ok, so – Cardinal Rules Queries has recently had a beta release, you can find it here. It allows you to leverage the power of the rules engine in Sitecore to build queries based on Lucene.Net, and if you choose – other search tools. Please see my initial post Sitecore Rules Queries Pt I for a bit more information.
Following on from this, I thought I would write a quick article on how you actually use it in code. Please note this is subject to change, but is correct at the time of posting.
During the course of the Sitecore installations (versions 6.2 – 7.2) I have been involved with, I have been asked to allow users to be able to select the results of their data for themselves. In later versions Sitecore have achieved this using the newer Search dialogs. I will come out and state that I haven’t really found the search dialogs too helpful as a user myself, and that I don’t see the content editors using them all that much either.
It has struck me since I first began using Sitecore that the rules engine could be an obvious potential solution to this issue. The basis being that you create a ‘query’ item, this item is then used as a datasource / basis item for your renderings (or sublayouts in older installations). I also considered the idea of combining the rules engine with Lucene / Solr in order to retrieve results based on the selection the user makes – after all, that’s what we are kinda doing as developers in any case.
I first started messing with the rules engine – shown in this post Searching with the rules engine in Sitecore. This was great and really started to show the potential. I also realised quickly that users would need to be able to test their queries from within the engine, so after a little work, I settled on a dialog that looked like this:
Just for fun – the core engine that drives this is using a simple visitor pattern and could be utilised for other data – I am currently also experimenting with my mongo L2 cache with extended linking 😀
In the next post, I will describe how to use the results of your rules queries in renderings / sublayouts or other tasks.
EDIT: For those who dont know, you can find Rules Queries for Sitecore here on Github
In this post I will be looking at how to drive a lucene search by using the Sitecore Rules engine.
Pretty much since I started using Sitecore, I have found that Lucene has been the get out of jail when it comes to performance. In fact, I can’t remember the last time I used Sitecore queries or the item axes. As a developer I have always been happy to write such methods as GetDescendants(ID itemId, ID templateId).
What about giving this power to the user though?
The rules engine in its default form is a great tool but executing a rule against a bunch of items becomes a iterative process and often can carry a performance penalty. This got me thinking – could I use the rules engine to drive the Sitecore Search Layer?