Пример #1
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());
        }
Пример #2
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);
            }
        }