private static IQueryable <T> AddExcludedTags <T>(IQueryable <T> query, IEnumerable <string> value)
            where T : LuceneSearchResultItem
        {
            if (value == null)
            {
                return(query);
            }

            var values = value.ToList();

            if (!values.Any())
            {
                return(query);
            }

            query =
                query.AddFilter(
                    new AndAllAggregateFilter <T>(values.Select(s => new ExcludeContentTagFilter <T>(s))));

            query =
                query.AddFilter(
                    new AndAllAggregateFilter <T>(values.Select(s => new ExcludeAutomatedTagFilter <T>(s))));

            return(query);
        }
Exemplo n.º 2
0
        public void AddFilter()
        {
            Expression <Func <TestDataObject, bool> > e = (o) => o.BoolProperty == true;

            list = list.AddFilter(e);
            Assert.That(list.ToList().Count, Is.EqualTo(5));
        }
        private static IQueryable <T> AddCollectionSource <T>(IQueryable <T> query, ID path, SiteContext siteContext, bool isCollectionSearch)
            where T : LuceneSearchResultItem
        {
            // TODO: this is messy. "collection search" searches under a specific item
            // Sitesearch searches under Content and Media for the site.
            // Collection source should then be ID[] locations and not use a flag?
            if (isCollectionSearch)
            {
                // assign filter based on whether this is a scoped collection search or not
                // if search location not provided use current item
                if (path == ID.Null)
                {
                    path = Sitecore.Context.Item.ID;
                }

                query = query.AddFilter(new CollectionFilter <T>(path));
            }
            else
            {
                if (path == ID.Null)
                {
                    // no Path specified - search the whole site (Content and Media)
                    query = query.AddFilter(new DefaultFilter <T>(siteContext));
                }
                else
                {
                    // path was specified - search under the path
                    query = query.AddFilter(new CollectionFilter <T>(path));
                }
            }

            return(query);
        }
Exemplo n.º 4
0
        private IQueryable <TEntity> ApplyPermission(IQueryable <TEntity> contentQuery)
        {
            BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;

            // remove deleted records
            if (typeof(TEntity).GetProperty("IsDeleted", flags) != null)
            {
                contentQuery = contentQuery.AddFilter("IsDeleted", false);
            }
            if (_checkPermissions)
            {
                //remove inactive records
                if (!_permissions.Contains(PermissionEnum.ViewInactiveContent) && typeof(TEntity).GetProperty("IsActive", flags) != null)
                {
                    contentQuery = contentQuery.AddFilter("IsActive", true);
                }
                //ignore unapproved records as per permission
                if (!_permissions.Contains(PermissionEnum.ViewUnapprovedContent) && typeof(TEntity).GetProperty("ApprovalStatus", flags) != null)
                {
                    contentQuery = contentQuery.AddFilter("ApprovalStatus", WorkflowConstants.ApprovedStatus);
                }

                //ignore not allowed anomynous records
                if ((!_permissions.Contains(PermissionEnum.ViewContent) && _permissions.Contains(PermissionEnum.ViewAnomynousContent)) && typeof(TEntity).GetProperty("IsAnomynousAccess", flags) != null)
                {
                    contentQuery = contentQuery.AddFilter("IsAnomynousAccess", true);
                }
            }
            return(contentQuery);
        }
Exemplo n.º 5
0
        public IQueryable <Entity.User> GenerateQuery(IQueryable <Entity.User> query)
        {
            query = query.AddFilter(o => o.UserRoleMapping.Any(x => x.RoleId == this.RoleId), this.RoleId);
            query = query.AddFilter(o => o.IsEnable == this.IsEnable, this.IsEnable);
            query = query.AddFilter(o => o.IsLocked, this.IsLocked);
            query = query.AddFilter(o => o.DisplayName.Contains(this.DisplayName), this.DisplayName);
            query = query.AddFilter(o => o.LoginName.Contains(this.LoginName), this.LoginName);
            query = query.AddDateTimeBetweenFilter(this.StartCreateTime, this.EndCreateTime, o => o.CreateTime);

            query = query.OrderByDescending(o => o.CreateTime);
            return(query);
        }
Exemplo n.º 6
0
        public IActionResult Search(LogPostModel model)
        {
            using (this.DbContext)
            {
                IQueryable <Log> query = this.DbContext.Log.AsNoTracking();

                query = query.AddFilter(o => o.LogLevel == (int?)model.LogLevel, model.LogLevel);
                query = query.AddFilter(o => o.SqlOperateType == (int?)model.SqlType, model.SqlType);
                query = query.AddFilter(o => o.Message.Contains(model.Message), model.Message);
                query = query.AddDateTimeBetweenFilter(model.StartTime, model.EndTime, o => o.CreateTime);
                query = query.OrderByDescending(o => o.CreateTime);

                return(this.StandardSearchResponse(query, model, LogModel.Convert));
            }
        }
Exemplo n.º 7
0
        public IActionResult Search(IconPostModel model)
        {
            using (this.DbContext)
            {
                IQueryable <Icon> query = this.DbContext.Icon.AsNoTracking();
                query = query.AddStringContainsFilter(o => o.Code, model.Code);
                query = query.AddFilter(o => o.IsEnable, model.IsEnable);

                return(this.StandardResponse(query, model));
            }
        }
Exemplo n.º 8
0
        public IActionResult Search(MenuPostModel model)
        {
            using (this.DbContext)
            {
                IQueryable <Menu> query = this.DbContext.Menu.AsNoTracking();
                query = query.AddStringContainsFilter(o => o.Name, model.Name);
                query = query.AddStringContainsFilter(o => o.Description, model.Description);
                query = query.AddFilter(o => o.Status, model.Status);
                query = query.AddDateTimeBetweenFilter(model.StartCreateTime, model.EndCreateTime, o => o.CreateTime);
                query = query.OrderByDescending(o => o.CreateTime);

                return(this.StandardSearchResponse(query, model, MenuModel.Convert));
            }
        }
        private static IQueryable <T> AddExcludedItems <T>(IQueryable <T> query, IEnumerable <ID> value)
            where T : LuceneSearchResultItem
        {
            if (value == null)
            {
                return(query);
            }

            var values = value.ToList();

            if (!values.Any())
            {
                return(query);
            }

            return(query.AddFilter(new AndAllAggregateFilter <T>(values.Select(id => new ExcludeItemFilter <T>(id)))));
        }
        private static IQueryable <T> AddTemplates <T>(IQueryable <T> query, IEnumerable <ID> selectedTemplateIds)
            where T : LuceneSearchResultItem
        {
            if (selectedTemplateIds == null)
            {
                return(query);
            }

            var values = selectedTemplateIds.ToList();

            if (!values.Any())
            {
                return(query);
            }

            return(query.AddFilter(
                       new OrAnyAggregateFilter <T>(values.Select(s => new TemplateFilter <T>(s)))));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Override this method to apply a filter on the possible value query.
        /// </summary>
        /// <remarks>
        /// <para>If null is returned the query will be aborted and an empty list will be shown.</para>
        /// <para>To Apply no filter simply return the given query.</para>
        /// <para>The base implementation returns the query. So no need to call base.</para>
        /// </remarks>
        /// <param name="qry">Query to filter</param>
        /// <returns>filtered query or null</returns>
        protected virtual IQueryable ApplyFilter(IQueryable qry)
        {
            FetchFilterModels();
            if (_filterModels.Count == 0)
            {
                return(qry);
            }

            if (string.IsNullOrEmpty(SearchString))
            {
                if (_filterModels.Any(f => f.Required))
                {
                    return(null);
                }
                return(qry);
            }

            LambdaExpression tmp = null;

            foreach (FilterModel f in _filterModels)
            {
                var valMdl = f.FilterArgument.Value as ClassValueModel <string>;
                if (valMdl != null)
                {
                    valMdl.Value = SearchString;
                    var expr = f.GetExpression(qry);
                    if (tmp == null)
                    {
                        tmp = expr;
                    }
                    else
                    {
                        tmp = tmp.OrElse(expr);
                    }
                }
            }

            if (tmp == null)
            {
                return(qry);
            }
            return(qry.AddFilter(tmp));
        }