Example #1
0
        private IEnumerable <int> GetIdResultsWithNodeQuery(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort,
                                                            FilterStatus enableAutofilters, FilterStatus enableLifespanFilter, QueryExecutionMode executionMode)
        {
            //TODO: QUICK: Process executionMode in GetIdResultsWithNodeQuery
            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());
        }
Example #2
0
        public IEnumerable <LucObject> Execute(bool allVersions)
        {
            if (LucQuery.IsAutofilterEnabled(this.EnableAutofilters) || LucQuery.IsLifespanFilterEnabled(this.EnableLifespanFilter))
            {
                var fullQuery = new BooleanQuery();
                fullQuery.Add(new BooleanClause(this.Query, BooleanClause.Occur.MUST));

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

                this.Query = fullQuery;
            }

            using (var op = SnTrace.Query.StartOperation("LucQuery: {0}", this))
            {
                if (FieldLevel == QueryFieldLevel.NotDefined)
                {
                    FieldLevel = GetFieldLevel();
                }
                var permissionChecker = new PermissionChecker(this.User ?? AccessProvider.Current.GetCurrentUser(), FieldLevel, allVersions);

                this.QueryInfo = QueryClassifier.Classify(this, this.Top, this.Skip, this.SortFields, this.CountOnly, allVersions);

                IEnumerable <LucObject> result   = null;
                IQueryExecutor          executor = null;

                var executionAlgorithm = ForceLuceneExecution
                    ? ContentQueryExecutionAlgorithm.LuceneOnly
                    : Configuration.Querying.ContentQueryExecutionAlgorithm;

                switch (executionAlgorithm)
                {
                default:
                case ContentQueryExecutionAlgorithm.Default:
                case ContentQueryExecutionAlgorithm.Provider:
                {
                    executor = SearchProvider.GetExecutor(this);
                    executor.Initialize(this, permissionChecker);
                    result = Execute(executor);
                }
                break;

                case ContentQueryExecutionAlgorithm.LuceneOnly:
                {
                    executor = SearchProvider.GetFallbackExecutor(this);
                    executor.Initialize(this, permissionChecker);
                    result = Execute(executor);
                }
                break;

                case ContentQueryExecutionAlgorithm.Validation:
                {
                    executor = SearchProvider.GetExecutor(this);
                    executor.Initialize(this, permissionChecker);
                    result = Execute(executor);
                    if (!(executor is LuceneQueryExecutor))
                    {
                        var fallbackExecutor = SearchProvider.GetFallbackExecutor(this);
                        fallbackExecutor.Initialize(this, permissionChecker);
                        var expectedResult = Execute(fallbackExecutor);
                        AssertResultsAreEqual(expectedResult, result, fallbackExecutor.QueryString, executor.QueryString);
                    }
                }
                break;
                }

                op.Successful = true;
                return(result);
            }
        }
Example #3
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);
            }
        }