Ejemplo n.º 1
0
        // ========================================================================================

        public IEnumerable <LucObject> Execute(IPermissionFilter filter, IQueryContext context)
        {
            using (var op = SnTrace.Query.StartOperation("LucQuery: {0}", this))
            {
                IQueryExecutor executor;

                if (CountOnly)
                {
                    executor = new QueryExecutor20131012CountOnly();
                }
                else
                {
                    executor = new QueryExecutor20131012();
                }

                executor.Initialize(this, filter);

                var result = executor.Execute();
                TotalCount = executor.TotalCount;

                SnTrace.Query.Write("LucQuery.Execute total count: {0}", TotalCount);

                op.Successful = true;
                return(result ?? new LucObject[0]);
            }
        }
        public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var result = Retrier.Retry(SearchServiceClient.RetryCount, SearchServiceClient.RetryWaitMilliseconds, typeof(CommunicationException),
                                       () => SearchServiceClient.Instance.ExecuteQuery(query, GetQueryContext(query, context)));

            return(new QueryResult <int>(result.Hits, result.TotalCount));
        }
Ejemplo n.º 3
0
 public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     if (_intResults.TryGetValue(query.Querytext, out var result))
     {
         return(result);
     }
     return(QueryResult <int> .Empty);
 }
Ejemplo n.º 4
0
        //TODO: Part of 'CQL to SQL compiler' for future use.
        public QueryResult <int> TryExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            //var queryInfo = SnQueryClassifier.Classify(query, context.AllVersions);
            //if (SnLucToSqlCompiler.TryCompile(QueryInfo.Query.QueryTree, QueryInfo.Top, QueryInfo.Skip,
            //    QueryInfo.SortFields, QueryInfo.CountOnly, out _sqlQueryText, out _sqlParameters))

            return(null); // means: cannot execute
        }
        /// <inheritdoc />
        /// <summary>
        /// Executes the provided <see cref="T:SenseNet.Search.Querying.SnQuery" /> on the local Lucene index and returns results
        /// permitted by the provided permission filter.
        /// </summary>
        public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var lucQuery = Compile(query, context);

            var lucQueryResult = lucQuery.Execute(filter, context);
            var hits           = lucQueryResult?.Select(x => x.NodeId).ToArray() ?? new int[0];

            return(new QueryResult <int>(hits, lucQuery.TotalCount));
        }
Ejemplo n.º 6
0
 private static QueryResult <string> TryExecuteQueryAndProject(SnQuery query, IPermissionFilter permissionFilter, IQueryContext context)
 {
     try
     {
         return(context.MetaQueryEngine?.TryExecuteQueryAndProject(query, permissionFilter, context));
     }
     catch
     {
         return(null);
     }
 }
        public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var projection = query.Projection ?? IndexFieldName.NodeId;
            var converter  = !(context.GetPerFieldIndexingInfo(projection).IndexFieldHandler is IIndexValueConverter indexFieldHandler)
                ? DefaultConverter
                : indexFieldHandler.GetBack;

            var result = Retrier.Retry(SearchServiceClient.RetryCount, SearchServiceClient.RetryWaitMilliseconds, typeof(CommunicationException),
                                       () => SearchServiceClient.Instance.ExecuteQueryAndProject(query, GetQueryContext(query, context)));

            return(new QueryResult <string>(result.Hits.Select(h => converter(h)?.ToString()), result.TotalCount));
        }
        public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            _log.AppendLine($"ExecuteQueryAndProject: {query}");

            var interpreter = new SnQueryInterpreter(_index);
            var result      = interpreter.Execute(query, filter, out var totalCount);

            var projectedValues = result.Select(h => h.ValueForProject).Distinct().ToArray();
            var queryResult     = new QueryResult <string>(projectedValues, totalCount);

            return(queryResult);
        }
        public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            _log.AppendLine($"ExecuteQuery: {query}");

            var interpreter = new SnQueryInterpreter(_index);
            var result      = interpreter.Execute(query, filter, out var totalCount);

            var nodeIds     = result.Select(h => h.NodeId).ToArray();
            var queryResult = new QueryResult <int>(nodeIds, totalCount);

            return(queryResult);
        }
Ejemplo n.º 10
0
        public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            using (var op = SnTrace.Query.StartOperation("InMemoryQueryEngine: ExecuteQuery: {0}", query))
            {
                _log.AppendLine($"ExecuteQuery: {query}");

                var interpreter = new SnQueryInterpreter(this.Index);
                var result      = interpreter.Execute(query, filter, out var totalCount);

                var nodeIds     = result.Select(h => h.NodeId).ToArray();
                var queryResult = new QueryResult <int>(nodeIds, totalCount);

                op.Successful = true;
                return(queryResult);
            }
        }
        /// <inheritdoc />
        public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var lucQuery = Compile(query, context);

            var projection        = query.Projection ?? IndexFieldName.NodeId;
            var indexFieldHandler = context.GetPerFieldIndexingInfo(projection).IndexFieldHandler as IIndexValueConverter;
            var converter         = indexFieldHandler == null ? DefaultConverter : indexFieldHandler.GetBack;
            var lucQueryResult    = lucQuery.Execute(filter, context);
            var hits = lucQueryResult?
                       .Select(x => x[projection, false])
                       .Where(r => !string.IsNullOrEmpty(r))
                       .Select(q => converter(q).ToString())
                       .ToArray()
                       ?? new string[0];

            return(new QueryResult <string>(hits, lucQuery.TotalCount));
        }
Ejemplo n.º 12
0
        public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter,
                                                           IQueryContext context)
        {
            using (var op = SnTrace.Query.StartOperation("InMemoryQueryEngine: ExecuteQueryAndProject: {0}", query))
            {
                _log.AppendLine($"ExecuteQueryAndProject: {query}");

                var interpreter = new SnQueryInterpreter(this.Index);
                var result      = interpreter.Execute(query, filter, out var totalCount);

                var projectedValues = result.Select(h => h.ValueForProject).Distinct().ToArray();
                var queryResult     = new QueryResult <string>(projectedValues, totalCount);

                op.Successful = true;
                return(queryResult);
            }
        }
Ejemplo n.º 13
0
            public IEnumerable <Hit> Execute(SnQuery query, IPermissionFilter filter, out int totalCount)
            {
                Visit(query.QueryTree);

                if (_hitStack.Count == 0)
                {
                    throw new CompilerException("Compiler error: The stack does not contain any elements.");
                }
                if (_hitStack.Count != 1)
                {
                    throw new CompilerException($"Compiler error: The stack contains more than one elements ({_hitStack.Count}).");
                }

                var foundVersionIds = _hitStack.Pop();

                IEnumerable <Hit> permittedHits = foundVersionIds.Select(v => GetHitByVersionId(v, query.Projection, query.Sort)).Where(h => filter.IsPermitted(h.NodeId, h.IsLastPublic, h.IsLastDraft));
                var sortedHits = GetSortedResult(permittedHits, query.Sort).ToArray();

                totalCount = sortedHits.Length;

                var result = sortedHits.Skip(query.Skip).Take(query.Top > 0 ? query.Top : totalCount).ToArray();

                return(result);
            }
Ejemplo n.º 14
0
 /// <inheritdoc />
 public QueryResult <string> TryExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     return(null);
 }
Ejemplo n.º 15
0
 public void Initialize(LucQuery lucQuery, IPermissionFilter permissionChecker)
 {
     LucQuery          = lucQuery;
     PermissionChecker = permissionChecker;
 }
Ejemplo n.º 16
0
 /// <inheritdoc />
 public QueryResult <int> TryExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     return(null);
 }
Ejemplo n.º 17
0
 public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     return(QueryResult <int> .Empty);
 }
 public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
0
 public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
 {
     return(_stringResults[query.Querytext]);
 }