//====================================================================== Model

        protected override object GetModel()
        {
            var contextNode = GetContextNode();
            if (contextNode == null)
                return null;

            var smartFolder = Node.Load<SmartFolder>("/Root/System/RuntimeQuery");
            if (smartFolder == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/Root/System");
                    smartFolder = new SmartFolder(systemFolder) { Name = "RuntimeQuery" };
                    smartFolder.Save();
                }
            }

            var content = Content.Create(smartFolder);
            smartFolder.Query = string.Format("+InTree:\"{0}\" +TypeIs:Workspace -TypeIs:(Blog Wiki Site)", contextNode.Path);

            var baseModel = base.GetModel() as Content;
            if (baseModel != null)
            {
                content.ChildrenQueryFilter = baseModel.ChildrenQueryFilter;
                content.ChildrenQuerySettings = baseModel.ChildrenQuerySettings;
            }

            return content;
        }
Exemplo n.º 2
0
        protected override object GetModel()
        {
            var sf = Node.Load<SmartFolder>("/Root/System/RuntimeQuery");
            if (sf == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/root/system");
                    sf = new SmartFolder(systemFolder) { Name = "RuntimeQuery" };
                    sf.Save();
                }
            }

            var model = Content.Create(sf);
            if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString))
            {
                this.ErrorMessage = "Please give a more specific search text";
                return model;
            }

            sf.Query = ReplaceTemplates(this.QueryString);

            var baseModel = base.GetModel() as Content;
            if (baseModel != null)
            {
                model.ChildrenQueryFilter = baseModel.ChildrenQueryFilter;
                model.ChildrenQuerySettings = baseModel.ChildrenQuerySettings;

                if (FilterByContext)
                {
                    var ctx = GetContextNode();
                    if (ctx != null)
                    {
                        //add filter: we search only under the current context
                        var excapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)");

                        sf.Query = ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", excapedPath), ChainOperator.And);
                    }
                }
            }

            ResultModel = model;

            return model;
        }
        protected override object GetModel()
        {

            SmartFolder sf = null;
            sf = Node.Load<SmartFolder>("/Root/System/RuntimeQuery");
            if (sf == null)
            {
                using(new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/root/system");
                    sf = new SmartFolder(systemFolder) { Name = "RuntimeQuery" };
                    sf.Save();
                }
            }

            var c = ContentRepository.Content.Create(sf);
            sf.Query = ReplaceTemplates(this.QueryString);

            var oldc = base.GetModel() as ContentRepository.Content;
            if (oldc != null)
            {
                c.ChildrenQueryFilter = oldc.ChildrenQueryFilter;
                c.ChildrenQuerySettings = oldc.ChildrenQuerySettings;
            }

            return c;
        }