Exemplo n.º 1
0
        public async Task <ActionResult <ProductIndexedSearchResult> > SearchProducts([FromBody] ProductIndexedSearchCriteria criteria)
        {
            criteria.ObjectType = KnownDocumentTypes.Product;
            var result = await _productIndexedSearchService.SearchAsync(criteria);

            return(Ok(result));
        }
        public async Task <ActionResult <ProductIndexedSearchResult> > SearchProducts([FromBody] ProductIndexedSearchCriteria criteria)
        {
            criteria.ObjectType = KnownDocumentTypes.Product;
            var result = await _productIndexedSearchService.SearchAsync(criteria);

            //It is a important to return serialized data by such way. Instead you have a slow response time for large outputs
            //https://github.com/dotnet/aspnetcore/issues/19646
            return(Content(JsonConvert.SerializeObject(result, _jsonOptions.SerializerSettings), "application/json"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <ListEntrySearchResult> > ListItemsSearchAsync([FromBody] CatalogListEntrySearchCriteria criteria)
        {
            var result           = new ListEntrySearchResult();
            var useIndexedSearch = _settingsManager.GetValue(ModuleConstants.Settings.Search.UseCatalogIndexedSearchInManager.Name, true);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, criteria, new CatalogAuthorizationRequirement(ModuleConstants.Security.Permissions.Read));

            if (!authorizationResult.Succeeded)
            {
                return(Unauthorized());
            }

            if (useIndexedSearch && !string.IsNullOrEmpty(criteria.Keyword))
            {
                // TODO: create outline for category
                // TODO: implement sorting

                var categoryIndexedSearchCriteria = AbstractTypeFactory <CategoryIndexedSearchCriteria> .TryCreateInstance().FromListEntryCriteria(criteria) as CategoryIndexedSearchCriteria;

                const CategoryResponseGroup catResponseGroup = CategoryResponseGroup.Info | CategoryResponseGroup.WithOutlines;
                categoryIndexedSearchCriteria.ResponseGroup = catResponseGroup.ToString();

                var catIndexedSearchResult = await _categoryIndexedSearchService.SearchAsync(categoryIndexedSearchCriteria);

                var totalCount = catIndexedSearchResult.TotalCount;
                var skip       = Math.Min(totalCount, criteria.Skip);
                var take       = Math.Min(criteria.Take, Math.Max(0, totalCount - criteria.Skip));

                result.Results = catIndexedSearchResult.Items.Select(x => AbstractTypeFactory <CategoryListEntry> .TryCreateInstance().FromModel(x)).ToList();

                criteria.Skip -= (int)skip;
                criteria.Take -= (int)take;

                const ItemResponseGroup itemResponseGroup = ItemResponseGroup.ItemInfo | ItemResponseGroup.Outlines;

                var productIndexedSearchCriteria = AbstractTypeFactory <ProductIndexedSearchCriteria> .TryCreateInstance().FromListEntryCriteria(criteria) as ProductIndexedSearchCriteria;

                productIndexedSearchCriteria.ResponseGroup = itemResponseGroup.ToString();

                var indexedSearchResult = await _productIndexedSearchService.SearchAsync(productIndexedSearchCriteria);

                result.TotalCount += (int)indexedSearchResult.TotalCount;
                result.Results.AddRange(indexedSearchResult.Items.Select(x => AbstractTypeFactory <ProductListEntry> .TryCreateInstance().FromModel(x)));
            }
            else
            {
                result = await _listEntrySearchService.SearchAsync(criteria);
            }
            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <ListEntrySearchResult> > ListItemsSearchAsync([FromBody] CatalogListEntrySearchCriteria criteria)
        {
            //TODO:
            //ApplyRestrictionsForCurrentUser(coreModelCriteria);
            var result           = new ListEntrySearchResult();
            var useIndexedSearch = _settingsManager.GetValue(ModuleConstants.Settings.Search.UseCatalogIndexedSearchInManager.Name, true);

            if (useIndexedSearch && !string.IsNullOrEmpty(criteria.Keyword))
            {
                // TODO: create outline for category
                // TODO: implement sorting

                const ItemResponseGroup responseGroup = ItemResponseGroup.ItemInfo | ItemResponseGroup.Outlines;

                var productIndexedSearchCriteria = AbstractTypeFactory <ProductIndexedSearchCriteria> .TryCreateInstance();

                productIndexedSearchCriteria.ObjectType    = KnownDocumentTypes.Product;
                productIndexedSearchCriteria.Keyword       = criteria.Keyword;
                productIndexedSearchCriteria.CatalogId     = criteria.CatalogId;
                productIndexedSearchCriteria.Outline       = criteria.CategoryId;
                productIndexedSearchCriteria.WithHidden    = !criteria.HideDirectLinkedCategories;
                productIndexedSearchCriteria.Skip          = criteria.Skip;
                productIndexedSearchCriteria.Take          = criteria.Take;
                productIndexedSearchCriteria.ResponseGroup = responseGroup.ToString();
                productIndexedSearchCriteria.Sort          = criteria.Sort;

                var indexedSearchResult = await _productIndexedSearchService.SearchAsync(productIndexedSearchCriteria);

                result.TotalCount = (int)indexedSearchResult.TotalCount;
                result.Results    = indexedSearchResult.Items.Select(x => AbstractTypeFactory <ProductListEntry> .TryCreateInstance().FromModel(x)).ToList();
            }
            else
            {
                result = await _listEntrySearchService.SearchAsync(criteria);
            }
            return(Ok(result));
        }
Exemplo n.º 5
0
        protected virtual async Task <IQueryable <PriceEntity> > BuildQueryAsync(IPricingRepository repository, PricesSearchCriteria criteria)
        {
            var query = repository.Prices;

            if (!criteria.PriceListIds.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.PriceListIds.Contains(x.PricelistId));
            }

            if (!criteria.ProductIds.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.ProductIds.Contains(x.ProductId));
            }

            if (criteria.ModifiedSince.HasValue)
            {
                query = query.Where(x => x.ModifiedDate >= criteria.ModifiedSince);
            }

            if (!string.IsNullOrEmpty(criteria.Keyword))
            {
                var searchCriteria = AbstractTypeFactory <ProductIndexedSearchCriteria> .TryCreateInstance();

                searchCriteria.Keyword       = criteria.Keyword;
                searchCriteria.Skip          = criteria.Skip;
                searchCriteria.Take          = criteria.Take;
                searchCriteria.Sort          = criteria.Sort.Replace("product.", string.Empty);
                searchCriteria.ResponseGroup = ItemResponseGroup.ItemInfo.ToString();
                var searchResult = await _productIndexedSearchService.SearchAsync(searchCriteria);

                var productIds = searchResult.Items.Select(x => x.Id).ToArray();

                query = query.Where(x => productIds.Contains(x.ProductId));
            }

            return(query);
        }