This blog post explains how you can add support for relative fast queries when looking up items to populate selection fields for data templates in the Sitecore ASP.NET CMS.
You can run Sitecore queries relative to items, but you can only run fast queries against an entire database. For example, if the Source property of a Multilist field in the /sitecore/content/Home item contains a value such as the following:
You will experience an exception such as the following when you navigate to the /sitecore/content/Home item in the Content Editor:
Invalid lookup source "query:fast:.//*[@@templatekey='sample item']": End of string expected at position 4
To enable support for some types of relative fast queries, you can convert tokens that indicate relative paths to full paths before processing fast queries. To enable support for relative fast queries, you can add a processor such as the following to the getLookupSourceItems pipeline:
SC = Sitecore;
SC.Data.Items.Item item = args.Item;
path = args.Source.Substring(
item = item.Parent;
path = path.Substring(
+ item.Paths.FullPath +
Now when you access the /sitecore/content/Home item, the processor expands the query to the following before a the default ProcessQuerySource processor processes that query:
You can use similar logic wherever you need to invoke a relative fast query. Remember to consider the limitations of fast query and always test whether fast query outperforms Sitecore query (before evaluating performance, run the query to ensure Sitecore has cached the items).
To enable this processor, you can use a Web.config include file such as the following (Sitecore.Sharedsource.HandleRelativeFastQuery.config in my case), which must appear before the default ProcessQuerySource processor in that pipeline:
Note that there may be types of relative queries that this does not support, such as queries that start with an XPath axis such as self, parent, or ancestor-or-self.
Prefixing 'query:' in the datasource query is the important step. If you miss it, the pipeline gets executed, however query does not.