Пример #1
0
 public PermissionFilter(SnQuery query, IQueryContext context)
 {
     _userId          = context.UserId;
     _user            = Node.LoadNode(_userId) as IUser;
     _queryFieldLevel = GetFieldLevel(query);
     _allVersions     = query.AllVersions;
 }
Пример #2
0
        public static QueryFieldLevel GetFieldLevel(SnQuery query)
        {
            var v = new FieldNameVisitor();

            v.Visit(query.QueryTree);
            return(GetFieldLevel(v.FieldNames));
        }
Пример #3
0
        internal static void PrepareQuery(SnQuery query, IQueryContext context)
        {
            if (query.FiltersPrepared)
            {
                return;
            }

            var autoFiltersEnabled     = IsAutofilterEnabled(query.EnableAutofilters);
            var lifespanFiltersEnabled = IsLifespanFilterEnabled(query.EnableLifespanFilter);

            if (autoFiltersEnabled || lifespanFiltersEnabled)
            {
                var topLevelPredicate = new LogicalPredicate();
                topLevelPredicate.Clauses.Add(new LogicalClause(query.QueryTree, Occurence.Must));

                if (autoFiltersEnabled)
                {
                    topLevelPredicate.Clauses.Add(new LogicalClause(GetAutoFilterClause(context), Occurence.Must));
                }
                if (lifespanFiltersEnabled)
                {
                    topLevelPredicate.Clauses.Add(new LogicalClause(GetLifespanFilterClause(context), Occurence.Must));
                }

                query.QueryTree = topLevelPredicate;
            }

            query.FiltersPrepared = true;
        }
Пример #4
0
 private static QueryResult <string> TryExecuteQueryAndProject(SnQuery query, IPermissionFilter permissionFilter, IQueryContext context)
 {
     try
     {
         return(context.MetaQueryEngine?.TryExecuteQueryAndProject(query, permissionFilter, context));
     }
     catch
     {
         return(null);
     }
 }
Пример #5
0
        /// <summary>
        /// Analyzes a parsed SnQuery.
        /// </summary>
        /// <param name="query">The input query object</param>
        /// <returns>An SnQueryInfo instance as a result of the analysis.</returns>
        public static SnQueryInfo Classify(SnQuery query)
        {
            var sortfieldNames = query.Sort?.Select(x => x.FieldName).ToList() ?? new List <string>();
            var queryInfo      = new SnQueryInfo
            {
                Query          = query,
                SortFields     = query.Sort,
                Top            = query.Top,
                Skip           = query.Skip,
                SortFieldNames = sortfieldNames,
                CountAllPages  = query.CountAllPages,
                CountOnly      = query.CountOnly,
                AllVersions    = query.AllVersions
            };

            var visitor = new QueryClassifierVisitor(queryInfo);

            visitor.Visit(query.QueryTree);

            return(queryInfo);
        }
Пример #6
0
        internal static SnQuery ApplyVisitors(SnQuery query)
        {
            var queryTree = query.QueryTree;

            var visitorTypes = SnQueryVisitor.VisitorExtensionTypes;

            if (visitorTypes == null || visitorTypes.Length == 0)
            {
                return(query);
            }

            foreach (var visitorType in SnQueryVisitor.VisitorExtensionTypes)
            {
                var visitor = (SnQueryVisitor)Activator.CreateInstance(visitorType);
                queryTree = visitor.Visit(queryTree);
            }

            if (ReferenceEquals(queryTree, query.QueryTree))
            {
                return(query);
            }

            var newQuery = Create(queryTree);

            newQuery.Querytext            = query.Querytext;
            newQuery.Projection           = query.Projection;
            newQuery.Top                  = query.Top;
            newQuery.Skip                 = query.Skip;
            newQuery.Sort                 = query.Sort;
            newQuery.EnableAutofilters    = query.EnableAutofilters;
            newQuery.EnableLifespanFilter = query.EnableLifespanFilter;
            newQuery.CountOnly            = query.CountOnly;
            newQuery.QueryExecutionMode   = query.QueryExecutionMode;
            newQuery.AllVersions          = query.AllVersions;
            newQuery.CountAllPages        = query.CountAllPages;
            newQuery.ThrowIfEmpty         = query.ThrowIfEmpty;
            newQuery.ExistenceOnly        = query.ExistenceOnly;

            return(newQuery);
        }