public async Task <bool> FetchAsync()
        {
            if (_dataQuery.ListEntries.IsNullOrEmpty())
            {
                if (_dataQuery.SearchCriteria == null)
                {
                    Items = Array.Empty <IEntity>();
                }
                else
                {
                    var searchCriteria = BuildSearchCriteria(_dataQuery);
                    var searchResult   = await _listEntrySearchService.SearchAsync(searchCriteria);

                    Items = searchResult.ListEntries;
                }
            }
            else
            {
                var skip     = GetSkip();
                var take     = GetTake();
                var entities = await GetNextItemsAsync(_dataQuery.ListEntries, skip, take);

                Items = entities.ToArray();
            }

            _pageNumber++;

            return(Items.Any());
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> BulkCreateLinks([FromBody] BulkLinkCreationRequest creationRequest)
        {
            if (creationRequest.CatalogId.IsNullOrEmpty())
            {
                return(BadRequest("Target catalog identifier should be specified."));
            }

            var  searchCriteria = creationRequest.SearchCriteria;
            bool haveProducts;

            do
            {
                var searchResult = await _listEntrySearchService.SearchAsync(searchCriteria);

                var hasLinkEntries = await LoadCatalogEntriesAsync <IHasLinks>(searchResult.ListEntries.Select(x => x.Id).ToArray());

                haveProducts = hasLinkEntries.Any();

                searchCriteria.Skip += searchCriteria.Take;

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

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

                foreach (var hasLinkEntry in hasLinkEntries)
                {
                    var link = AbstractTypeFactory <CategoryLink> .TryCreateInstance();

                    link.CategoryId = creationRequest.CategoryId;
                    link.CatalogId  = creationRequest.CatalogId;
                    hasLinkEntry.Links.Add(link);
                }

                if (haveProducts)
                {
                    await SaveListCatalogEntitiesAsync(hasLinkEntries.ToArray());
                }
            } while (haveProducts);

            return(Ok());
        }
Ejemplo 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));
        }
        private async Task <ListEntrySearchResult> SearchProductsInCategoriesAsync(string[] categoryIds, int skip, int take)
        {
            var searchCriteria = AbstractTypeFactory <CatalogListEntrySearchCriteria> .TryCreateInstance();

            searchCriteria.CategoryIds        = categoryIds;
            searchCriteria.Skip               = skip;
            searchCriteria.Take               = take;
            searchCriteria.ResponseGroup      = ItemResponseGroup.Full.ToString();
            searchCriteria.SearchInChildren   = true;
            searchCriteria.SearchInVariations = true;

            var result = await _listEntrySearchService.SearchAsync(searchCriteria);

            return(result);
        }
        protected virtual async Task LoadCategoriesSitemapItemRecordsAsync(Store store, Sitemap sitemap, string baseUrl, Action <ExportImportProgressInfo> progressCallback = null)
        {
            var progressInfo = new ExportImportProgressInfo();

            var productOptions  = GetProductOptions();
            var categoryOptions = GetCategoryOptions();
            var batchSize       = SettingsManager.GetValue(ModuleConstants.Settings.General.SearchBunchSize.Name, (int)ModuleConstants.Settings.General.SearchBunchSize.DefaultValue);

            var categorySitemapItems = sitemap.Items.Where(x => x.ObjectType.EqualsInvariant(SitemapItemTypes.Category))
                                       .ToList();

            if (categorySitemapItems.Count > 0)
            {
                progressInfo.Description = $"Catalog: Starting records generation for {categorySitemapItems.Count} category items";
                progressCallback?.Invoke(progressInfo);

                foreach (var categorySiteMapItem in categorySitemapItems)
                {
                    var totalCount = 0;
                    var listEntrySearchCriteria = AbstractTypeFactory <CatalogListEntrySearchCriteria> .TryCreateInstance();

                    listEntrySearchCriteria.CategoryId = categorySiteMapItem.ObjectId;
                    listEntrySearchCriteria.Take       = batchSize;
                    listEntrySearchCriteria.HideDirectLinkedCategories = true;
                    listEntrySearchCriteria.SearchInChildren           = true;
                    listEntrySearchCriteria.WithHidden = false;

                    do
                    {
                        var result = await _listEntrySearchService.SearchAsync(listEntrySearchCriteria);

                        totalCount = result.TotalCount;
                        listEntrySearchCriteria.Skip += batchSize;
                        foreach (var listEntry in result.Results)
                        {
                            categorySiteMapItem.ItemsRecords.AddRange(GetSitemapItemRecords(store, categoryOptions, sitemap.UrlTemplate, baseUrl, listEntry));
                        }
                        progressInfo.Description = $"Catalog: Have been generated  { Math.Min(listEntrySearchCriteria.Skip, totalCount) } of {totalCount} records for category { categorySiteMapItem.Title } item";
                        progressCallback?.Invoke(progressInfo);
                    }while (listEntrySearchCriteria.Skip < totalCount);
                }
            }
        }