Ejemplo n.º 1
0
 private LucQuery()
 {
     TraceInfo = new QueryTraceInfo();
 }
Ejemplo n.º 2
0
 private LucQuery()
 {
     EnableAutofilters = true;
     EnableLifespanFilter = false;
     TraceInfo = new QueryTraceInfo();
 }
Ejemplo n.º 3
0
            private static InnerQueryResult ExecuteInnerScript(string src, int top, int skip,
                                                               IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter,
                                                               QuerySettings settings, bool enableProjection, out int count, out QueryTraceInfo traceInfo)
            {
                LucQuery query;

                try
                {
                    query = LucQuery.Parse(src);
                }
                catch (ParserException ex)
                {
                    throw new InvalidContentQueryException(src, innerException: ex);
                }

                var projection = query.Projection;

                if (projection != null)
                {
                    if (!enableProjection)
                    {
                        throw new ApplicationException(String.Format("Projection in top level query is not allowed ({0}:{1})", Parser.SnLucLexer.Keywords.Select, projection));
                    }
                }

                if (skip != 0)
                {
                    query.Skip = skip;
                }

                if (top != 0)
                {
                    query.PageSize = top;
                }
                else
                if (query.PageSize == 0)
                {
                    query.PageSize = GetDefaultMaxResults();
                }

                if (sort != null && sort.Count() > 0)
                {
                    query.SetSort(sort);
                }

                if (enableAutofilters != FilterStatus.Default)
                {
                    query.EnableAutofilters = enableAutofilters;
                }
                if (enableLifespanFilter != FilterStatus.Default)
                {
                    query.EnableLifespanFilter = enableLifespanFilter;
                }

                //Re-set settings values. This is important for NodeList that
                //uses the paging info written into the query text.
                if (settings != null)
                {
                    settings.Top  = query.PageSize;
                    settings.Skip = query.Skip;
                }

                InnerQueryResult result;

                var qresult = query.Execute().ToList();

                if (projection == null || !enableProjection)
                {
                    var idResult = qresult.Select(o => o.NodeId).ToArray();
                    result = new InnerQueryResult {
                        IsIntArray = true, IntArray = idResult, StringArray = idResult.Select(i => i.ToString()).ToArray()
                    };
                }
                else
                {
                    var stringResult = qresult.Select(o => o[projection, false]).Where(r => !String.IsNullOrEmpty(r));
                    var escaped      = new List <string>();
                    foreach (var s in stringResult)
                    {
                        escaped.Add(EscapeForQuery(s));
                    }
                    result = new InnerQueryResult {
                        IsIntArray = false, StringArray = escaped.ToArray()
                    };
                }

                traceInfo = query.TraceInfo;
                count     = query.TotalCount;

                return(result);
            }
Ejemplo n.º 4
0
 private LucQuery()
 {
     EnableAutofilters    = true;
     EnableLifespanFilter = false;
     TraceInfo            = new QueryTraceInfo();
 }
Ejemplo n.º 5
0
            private static InnerQueryResult ExecuteInnerScript(string src, int top, int skip,
                IEnumerable<SortInfo> sort, bool? enableAutofilters, bool? enableLifespanFilter, 
                QuerySettings settings, bool enableProjection, out int count, out QueryTraceInfo traceInfo)
            {
                var query = LucQuery.Parse(src);

                var projection = query.Projection;
                if (projection != null)
                    if (!enableProjection)
                        throw new ApplicationException(String.Format("Projection in top level query is not allowed ({0}:{1})", Parser.SnLucLexer.Keywords.Select, projection));

                if (skip != 0)
                    query.Skip = skip;

                if (top != 0)
                    query.PageSize = top;
                else
                    if (query.PageSize == 0)
                        query.PageSize = GetDefaultMaxResults();

                if (sort != null && sort.Count() > 0)
                    query.SetSort(sort);

                if (enableAutofilters.HasValue)
                    query.EnableAutofilters = enableAutofilters.Value;
                if (enableLifespanFilter.HasValue)
                    query.EnableLifespanFilter = enableLifespanFilter.Value;

                //Re-set settings values. This is important for NodeList that
                //uses the paging info written into the query text.
                if (settings != null)
                {
                    settings.Top = query.PageSize;
                    settings.Skip = query.Skip;
                }

                InnerQueryResult result;

                var qresult = query.Execute().ToList();
                if (projection == null || !enableProjection)
                {
                    var idResult = qresult.Select(o => o.NodeId).ToArray();
                    result = new InnerQueryResult { IsIntArray = true, IntArray = idResult, StringArray = idResult.Select(i => i.ToString()).ToArray() };
                }
                else
                {
                    var stringResult = qresult.Select(o => o[projection, false]).Where(r => !String.IsNullOrEmpty(r));
                    var escaped = new List<string>();
                    foreach (var s in stringResult)
                        escaped.Add(EscapeForQuery(s));
                    result = new InnerQueryResult { IsIntArray = false, StringArray = escaped.ToArray() };
                }

                traceInfo = query.TraceInfo;
                count = query.TotalCount;

                return result;
            }