Esempio n. 1
0
        public IEnumerable <int> Execute(string lucQuery)
        {
            var query      = LucQuery.Parse(lucQuery);
            var lucObjects = query.Execute();

            return(from lucObject in lucObjects select lucObject.NodeId);
        }
Esempio n. 2
0
        public static IEnumerable <LucObject> GetAllDocumentVersionsByNodeId(int nodeId)
        {
            var queryText = String.Concat(LucObject.FieldName.NodeId, ":", nodeId, " .AUTOFILTERS:OFF");
            var query     = LucQuery.Parse(queryText);
            var result    = query.Execute(true);

            return(result);
        }
Esempio n. 3
0
        //public object GetIndexDocumentInfo(Node node)
        //{
        //    return IndexDocumentInfo.Create(node);
        //}
        public IEnumerable <int> Execute(NodeQuery nodeQuery)
        {
            var query      = LucQuery.Create(nodeQuery);
            var lucObjects = query.Execute();

            return(from lucObject in lucObjects select lucObject.NodeId);
            //return from lucObject in lucObjects select lucObject.VersionId;
        }
Esempio n. 4
0
        public void AddOrClause(LucQuery q2)
        {
            var boolQ = new BooleanQuery();

            boolQ.Add(Query, BooleanClause.Occur.SHOULD);
            boolQ.Add(q2.Query, BooleanClause.Occur.SHOULD);
            Query = boolQ;
        }
Esempio n. 5
0
        public void AddAndClause(LucQuery q2)
        {
            var boolQ = new BooleanQuery();

            boolQ.Add(Query, BooleanClause.Occur.MUST);
            boolQ.Add(q2.Query, BooleanClause.Occur.MUST);
            Query = boolQ;
        }
Esempio n. 6
0
        internal static LucQuery Create(Query luceneQuery, QueryFieldLevel level)
        {
            var query = new LucQuery {
                Query = luceneQuery
            };

            query.TraceInfo.InputText = "";
            query.FieldLevel          = level;
            return(query);
        }
Esempio n. 7
0
        private IEnumerable <int> GetIdResultsWithNodeQuery(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort,
                                                            FilterStatus enableAutofilters, FilterStatus enableLifespanFilter)
        {
            var queryText = LucQuery.IsAutofilterEnabled(enableAutofilters) ? AddAutofilterToNodeQuery(Text) : Text;

            if (LucQuery.IsLifespanFilterEnabled(enableLifespanFilter))
            {
                queryText = AddLifespanFilterToNodeQuery(queryText, GetLifespanFilterForNodeQuery());
            }

            NodeQuery query;

            try
            {
                query = NodeQuery.Parse(queryText);
            }
            catch (XmlException ex)
            {
                throw new InvalidContentQueryException(queryText, innerException: ex);
            }
            catch (InvalidOperationException ex)
            {
                throw new InvalidContentQueryException(queryText, innerException: ex);
            }

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

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

            query.PageSize = query.Top;

            if (sort != null && sort.Count() > 0)
            {
                throw new NotSupportedException("Sorting override is not allowed on NodeQuery");
            }

            var result = query.Execute(hint);

            TotalCount = result.Count;

            return(result.Identifiers.ToList());
        }
Esempio n. 8
0
        public static LucQuery Create(NodeQuery nodeQuery)
        {
            NodeQueryParameter[] parameters;
            var result = new LucQuery();

            result.TraceInfo.BeginCrossCompilingTime();

            SortField[] sortFields;
            string      oldQueryText;

            try
            {
                var compiler          = new SnLucCompiler();
                var compiledQueryText = compiler.Compile(nodeQuery, out parameters);

                sortFields = (from order in nodeQuery.Orders
                              select new SortField(
                                  GetFieldNameByPropertyName(order.PropertyName),
                                  GetSortType(order.PropertyName), //SortField.STRING,
                                  order.Direction == OrderDirection.Desc)).ToArray();

                oldQueryText = compiler.CompiledQuery.ToString();
                oldQueryText = oldQueryText.Replace("[*", "[ ").Replace("*]", " ]").Replace("{*", "{ ").Replace("*}", " }");
                result.TraceInfo.InputText = oldQueryText;
            }
            finally
            {
                result.TraceInfo.FinishCrossCompilingTime();
            }
            result.TraceInfo.BeginParsingTime();
            Query newQuery;

            try
            {
                newQuery = new SnLucParser().Parse(oldQueryText);
            }
            finally
            {
                result.TraceInfo.FinishParsingTime();
            }
            result.Query                = newQuery; // compiler.CompiledQuery,
            result.User                 = nodeQuery.User;
            result.SortFields           = sortFields;
            result.StartIndex           = nodeQuery.Skip;
            result.PageSize             = nodeQuery.PageSize;
            result.Top                  = nodeQuery.Top;
            result.EnableAutofilters    = FilterStatus.Disabled;
            result.EnableLifespanFilter = FilterStatus.Disabled;

            return(result);
        }
Esempio n. 9
0
        public IEnumerable <LucObject> Execute(LucQuery lucQuery, bool allVersions)
        {
            this.LucQuery    = lucQuery;
            this.AllVersions = allVersions;
            using (var traceOperation = Logger.TraceOperation("Query execution", "Query: " + this.LucQuery.QueryText))
            {
                this.User = this.LucQuery.User;
                var currentUser = AccessProvider.Current.GetCurrentUser();
                if (this.User == null)
                {
                    this.User = currentUser;
                }
                var isCurrentUser = this.User.Id == currentUser.Id;

                Query currentQuery;

                if (LucQuery.IsAutofilterEnabled(this.LucQuery.EnableAutofilters) || LucQuery.IsLifespanFilterEnabled(this.LucQuery.EnableLifespanFilter))
                {
                    var fullQuery = new BooleanQuery();
                    fullQuery.Add(new BooleanClause(this.LucQuery.Query, BooleanClause.Occur.MUST));

                    if (LucQuery.IsAutofilterEnabled(this.LucQuery.EnableAutofilters))
                    {
                        fullQuery.Add(new BooleanClause(this.LucQuery.AutoFilterQuery, BooleanClause.Occur.MUST));
                    }
                    if (LucQuery.IsLifespanFilterEnabled(this.LucQuery.EnableLifespanFilter) && this.LucQuery.LifespanQuery != null)
                    {
                        fullQuery.Add(new BooleanClause(this.LucQuery.LifespanQuery, BooleanClause.Occur.MUST));
                    }

                    currentQuery = fullQuery;
                }
                else
                {
                    currentQuery = this.LucQuery.Query;
                }

                SearchResult r = null;
                using (var readerFrame = LuceneManager.GetIndexReaderFrame())
                {
                    BeginFullExecutingTime();

                    int top = this.LucQuery.Top != 0 ? this.LucQuery.Top : this.LucQuery.PageSize;
                    if (top == 0)
                    {
                        top = int.MaxValue;
                    }

                    var idxReader = readerFrame.IndexReader;
                    var searcher  = new IndexSearcher(idxReader);

                    var p = new SearchParams
                    {
                        query       = currentQuery,
                        allVersions = allVersions,
                        searcher    = searcher,
                        numDocs     = idxReader.NumDocs(),
                        timer       = timer,
                        top         = top,
                        executor    = this
                    };

                    try
                    {
                        r = DoExecute(p);
                    }
                    finally
                    {
                        if (p.searcher != null)
                        {
                            p.searcher.Close();
                            p.searcher = null;
                        }
                        FinishFullExecutingTime();
                    }
                }
                TotalCount = r.totalCount;

                var searchtimer = r.searchTimer;
                var trace       = lucQuery.TraceInfo;
                trace.KernelTime        = searchtimer.KernelTime;
                trace.CollectingTime    = searchtimer.CollectingTime;
                trace.PagingTime        = searchtimer.PagingTime;
                trace.FullExecutingTime = FullExecutingTime;
                trace.Searches          = r.searches;

                traceOperation.AdditionalObject = trace;
                traceOperation.IsSuccessful     = true;
                return(r.result);
            }
        }
Esempio n. 10
0
        public static LucQuery Parse(string luceneQueryText)
        {
            var result = new LucQuery();

            result.TraceInfo.InputText = luceneQueryText;

            result.TraceInfo.BeginParsingTime();
            var   parser = new SnLucParser();
            Query query;

            try
            {
                var replacedText = LucQueryTemplateReplacer.ReplaceTemplates(luceneQueryText);
                query = parser.Parse(replacedText);
            }
            finally
            {
                result.TraceInfo.FinishParsingTime();
            }
            //Run EmptyTermVisitor if the parser created empty query term.
            if (parser.ParseEmptyQuery)
            {
                var visitor = new EmptyTermVisitor();
                result.Query = visitor.Visit(query);
            }
            else
            {
                result.Query = query;
            }

            var sortFields = new List <SortField>();

            foreach (var control in parser.Controls)
            {
                switch (control.Name)
                {
                case SnLucLexer.Keywords.Select:
                    result.Projection = control.Value;
                    break;

                case SnLucLexer.Keywords.Top:
                    result.Top = Convert.ToInt32(control.Value);
                    break;

                case SnLucLexer.Keywords.Skip:
                    result.Skip = Convert.ToInt32(control.Value);
                    break;

                case SnLucLexer.Keywords.Sort:
                    sortFields.Add(CreateSortField(control.Value, false));
                    break;

                case SnLucLexer.Keywords.ReverseSort:
                    sortFields.Add(CreateSortField(control.Value, true));
                    break;

                case SnLucLexer.Keywords.Autofilters:
                    result.EnableAutofilters = control.Value == SnLucLexer.Keywords.On ? FilterStatus.Enabled : FilterStatus.Disabled;
                    break;

                case SnLucLexer.Keywords.Lifespan:
                    result.EnableLifespanFilter = control.Value == SnLucLexer.Keywords.On ? FilterStatus.Enabled : FilterStatus.Disabled;
                    break;

                case SnLucLexer.Keywords.CountOnly:
                    result.CountOnly = true;
                    break;
                }
            }
            result.SortFields = sortFields.ToArray();
            result.FieldLevel = parser.FieldLevel;
            return(result);
        }
Esempio n. 11
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);
            }
Esempio n. 12
0
        private IEnumerable <int> GetIdResultsWithLucQuery(int top, int skip, IEnumerable <SortInfo> sort,
                                                           FilterStatus enableAutofilters, FilterStatus enableLifespanFilter)
        {
            var queryText = Text;

            if (!queryText.Contains("}}"))
            {
                LucQuery query;

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

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

                query.Top = System.Math.Min(top == 0 ? int.MaxValue : top, query.Top == 0 ? int.MaxValue : query.Top);
                if (query.Top == 0)
                {
                    query.Top = GetDefaultMaxResults();
                }

                query.PageSize = query.Top;

                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.
                this.Settings.Top  = query.PageSize;
                this.Settings.Skip = query.Skip;
                //this.Settings.Sort = we don't need this

                this.TraceInfo = new[] { query.TraceInfo };

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

                TotalCount = query.TotalCount;

                return((from luco in lucObjects
                        select luco.NodeId).ToList());
            }
            else
            {
                List <string> log;
                int           count;
                IEnumerable <QueryTraceInfo> traceInfo;
                var result = RecursiveExecutor.ExecuteRecursive(queryText, top, skip,
                                                                sort, enableAutofilters, enableLifespanFilter, this.Settings, out count, out log, out traceInfo);

                TotalCount = count;

                this.TraceInfo = traceInfo;

                return(result);
            }
        }