Exemple #1
0
        public async Task <IResultList <IContentEntity> > DoAsync(IAppEntity app, ISchemaEntity schema, ClrQuery query, Status[]?status, bool inDraft, bool includeDraft = true)
        {
            Guard.NotNull(app);
            Guard.NotNull(schema);
            Guard.NotNull(query);

            try
            {
                query = query.AdjustToModel(schema.SchemaDef, inDraft);

                List <Guid>?fullTextIds = null;

                if (!string.IsNullOrWhiteSpace(query.FullText))
                {
                    fullTextIds = await indexer.SearchAsync(query.FullText, app, schema.Id, inDraft?Scope.Draft : Scope.Published);

                    if (fullTextIds?.Count == 0)
                    {
                        return(ResultList.CreateFrom <IContentEntity>(0));
                    }
                }

                var filter = CreateFilter(schema.Id, fullTextIds, status, query);

                var contentCount = Collection.Find(filter).CountDocumentsAsync();
                var contentItems =
                    Collection.Find(filter)
                    .WithoutDraft(includeDraft)
                    .QueryLimit(query)
                    .QuerySkip(query)
                    .QuerySort(query)
                    .ToListAsync();

                await Task.WhenAll(contentItems, contentCount);

                foreach (var entity in contentItems.Result)
                {
                    entity.ParseData(schema.SchemaDef, serializer);
                }

                return(ResultList.Create <IContentEntity>(contentCount.Result, contentItems.Result));
            }
            catch (MongoQueryException ex)
            {
                if (ex.Message.Contains("17406"))
                {
                    throw new DomainException("Result set is too large to be retrieved. Use $top parameter to reduce the number of items.");
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #2
0
        public async Task <IResultList <IContentEntity> > QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, bool inDraft, Query query, bool includeDraft = true)
        {
            Guard.NotNull(app, nameof(app));
            Guard.NotNull(schema, nameof(schema));
            Guard.NotNull(query, nameof(query));

            using (Profiler.TraceMethod <MongoContentRepository>("QueryAsyncByQuery"))
            {
                var fullTextIds = await indexer.SearchAsync(query.FullText, app, schema.Id, inDraft?Scope.Draft : Scope.Published);

                if (fullTextIds?.Count == 0)
                {
                    return(ResultList.CreateFrom <IContentEntity>(0));
                }

                return(await contents.QueryAsync(schema, query, fullTextIds, status, inDraft, includeDraft));
            }
        }