Query template replacer

During projects it is sometimes necessary to use custom query templates. For example, if you want to gather content that was created not longer ago than one year with respect to the current date. In lucene query this is impossible to define, but you can always create your own custom template replacer. The trick here is to inherit from LucQueryTemplateReplacer. Here is an example from the product:

 

public class PortalLucQueryTemplateReplacer : RepositoryLucQueryTemplateReplacer
    {
        private static readonly string[] objectNames = new[] { "currentsite""currentworkspace"
            "currentpage""currentcontent" };
 
        public override IEnumerable<string> ObjectNames
        {
            get { return objectNames; }
        }
 
        public override string EvaluateObjectProperty(string objectName, string propertyName)
        {
            if (HttpContext.Current == null || PortalContext.Current == null)
                return base.EvaluateObjectProperty(objectName, propertyName);
 
            switch (objectName.ToLower())
            {
                case "currentsite":
                    return GetProperty(PortalContext.Current.Site, propertyName);
                case "currentworkspace":
                    return GetProperty(PortalContext.Current.ContextWorkspace, propertyName);
                case "currentpage":
                    return GetProperty(PortalContext.Current.Page, propertyName);
                case "currentcontent":
                    return GetProperty(PortalContext.Current.ContextNode, propertyName);
                default:
                    return base.EvaluateObjectProperty(objectName, propertyName);
            }
        }
    }  

 

 

Comments (1) -

Miklós Tóth
9/18/2011 11:02:17 AM #

Check the wiki for more details Smile
wiki.sensenet.com/index.php

Comments are closed

Welcome to the blog!

Sense/Net ECM is ever evolving. Community means the world to us so we want to keep you apprised on what’s happening on our side of the woods. Want to make us happy? Add a comment and tell us what you think!

Month List