Exemple #1
0
        private async Task <long> RunCountQuery(CosmosQuery query, CancellationToken cancellationToken)
        {
            var queryDefinition = new QueryDefinition(query.ToString(true));
            var results         = await _connection.RunQueryAsync <JObject>(queryDefinition, _logger, cancellationToken);

            return((long)((JValue)results[0]["$1"]).Value);
        }
        internal virtual CosmosQuery AddGroup(CosmosQuery group)
        {
            if (_whereClause.Length > 0)
            {
                _whereClause.Append($" {_combinationOperator.ToString().ToUpper()} ");
            }

            _whereClause.Append($"({group._whereClause})");

            return(this);
        }
Exemple #3
0
        public async Task <SearchResult> SearchAsync(SearchRequest request, string entityType, DateTime pointInTime, CancellationToken cancellationToken)
        {
            // Build the query for use input
            var userQuery = new CosmosQuery(request.CombinationOperator.Equals("or") ? CosmosCombinationOperator.Or : CosmosCombinationOperator.And);

            foreach (var group in request.Groups)
            {
                var groupQuery = new CosmosQuery(group.CombinationOperator.Equals("or") ? CosmosCombinationOperator.Or : CosmosCombinationOperator.And);

                foreach (var filter in group.Filter)
                {
                    groupQuery.AddCondition(filter.Field, filter.Operator, filter.Value);
                }

                userQuery.AddGroup(groupQuery);
            }

            // Add system properties
            var query = new CosmosQuery(CosmosCombinationOperator.And)
                        .AddGroup(userQuery)
                        .AddTypeCondition(entityType)
                        .AddPointInTimeCondition(pointInTime)
                        .TakeResultsBetween(request.Skip, request.Take);

            // Get the results
            var results = await RunQuery(query, cancellationToken);

            var count = await RunCountQuery(query, cancellationToken);

            var mappedResults = results
                                .Select(x => _mapper.Map(x))
                                .ToArray();

            return(new SearchResult
            {
                Results = mappedResults,
                TotalNumberOfRecords = count,
            });
        }
Exemple #4
0
        private async Task <CosmosRegisteredEntity[]> RunQuery(CosmosQuery query, CancellationToken cancellationToken)
        {
            var queryDefinition = new QueryDefinition(query.ToString());

            return(await _connection.RunQueryAsync <CosmosRegisteredEntity>(queryDefinition, _logger, cancellationToken));
        }
Exemple #5
0
 public IDictionary <string, Type> GetSearchableFieldNames()
 {
     return(CosmosQuery.GetSearchablePropertyNames());
 }