Пример #1
0
        public async Task <IEnumerable <Tag> > Search(TagSearchRequest request)
        {
            var json = JsonConvert.SerializeObject(request);

            _logger.LogInformation($"tags.by.query ${json}");
            var data = (await _repository.SearchAsync(request)).ToList();

            _logger.LogInformation($"found.tags {data.Count}");
            return(data);
        }
Пример #2
0
        public async Task <IEnumerable <Tag> > SearchAsync(TagSearchRequest request)
        {
            var builder = Builders <Tag> .Filter;
            var filter  = builder.Empty;

            if (!string.IsNullOrEmpty(request.Query))
            {
                var regex = new BsonRegularExpression(request.Query, "i");
                filter &= builder.Regex(x => x.Name, regex);
            }

            if (request.Categories?.Length > 0)
            {
                filter &= builder.In(x => x.Category, request.Categories);
            }

            return(await _context.Tags
                   .Find(filter)
                   .Skip(request.Skip)
                   .Limit(request.Limit)
                   .ToListAsync());
        }