public static catalogDto.CategorySearchCriteria ToCategorySearchCriteriaDto(this CategorySearchCriteria criteria, WorkContext workContext) { var result = new catalogDto.CategorySearchCriteria { SearchPhrase = criteria.Keyword, LanguageCode = criteria.Language?.CultureName ?? workContext.CurrentLanguage.CultureName, StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, Outline = criteria.Outline, Sort = criteria.SortBy, Skip = criteria.Start, Take = criteria.PageSize, ResponseGroup = ((int)criteria.ResponseGroup).ToString(), }; var contact = workContext.CurrentUser?.Contact; if (contact != null && !contact.UserGroups.IsNullOrEmpty()) { if (result.UserGroups == null) { result.UserGroups = new List <string>(); } //search categories with user_groups defined in customer result.UserGroups.AddRange(contact.UserGroups); } return(result); }
public async Task <IHttpActionResult> SearchCategories(CategorySearchCriteria criteria) { criteria.ObjectType = KnownDocumentTypes.Category; var result = await _categorySearchService.SearchAsync(criteria); return(Ok(result)); }
public ActionResult ProductAdd() { CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.Type = (int)CommonEnum.TypeOfDbObject.Classification; SearchCriteria.ParentId = -1; var attrsTypes = this._ObjectService.SearchCategory(SearchCriteria).Item1; var typelist = (from m in attrsTypes select new SelectListItem { Text = m.Name, Value = m.Id.ToString() }).ToList(); if (typelist.Count == 0) { typelist.Add(new SelectListItem() { Text = "无", Value = "-1" }); } ViewBag.shopType = typelist; var model = new ProductViewModel(); return(View(model)); }
public async Task <CategorySearchResult> SearchCategoriesAsync(CategorySearchCriteria criteria) { var result = AbstractTypeFactory <CategorySearchResult> .TryCreateInstance(); using (var repository = _catalogRepositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var sortInfos = BuildSortExpression(criteria); var query = BuildQuery(repository, criteria); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0 && result.TotalCount > 0) { var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .ToArrayAsync(); result.Results = (await _categoryService.GetByIdsAsync(ids, criteria.ResponseGroup)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } } return(result); }
protected virtual void SetChildCategoriesLazyLoading(Category[] categories) { foreach (var category in categories) { //Lazy loading for parents categories category.Parents = new MutablePagedList <Category>((pageNumber, pageSize, sortInfos) => { var catIds = category.Outline.Split('/'); return(new StaticPagedList <Category>(GetCategories(catIds, CategoryResponseGroup.Small), pageNumber, pageSize, catIds.Length)); }, 1, CategorySearchCriteria.DefaultPageSize); //Lazy loading for child categories category.Categories = new MutablePagedList <Category>((pageNumber, pageSize, sortInfos) => { var categorySearchCriteria = new CategorySearchCriteria { PageNumber = pageNumber, PageSize = pageSize, Outline = "/" + category.Outline }; if (!sortInfos.IsNullOrEmpty()) { categorySearchCriteria.SortBy = SortInfo.ToString(sortInfos); } var searchResult = SearchCategories(categorySearchCriteria); return(searchResult); }, 1, CategorySearchCriteria.DefaultPageSize); } }
protected virtual async Task <SearchCriteria> GetSearchCriteriaAsync(GetCategoryBrowsingViewModelParam param) { var criteria = new CategorySearchCriteria { NumberOfItemsPerPage = param.NumberOfItemsPerPage, IncludeFacets = true, InventoryLocationIds = param.InventoryLocationIds, AvailabilityDate = FulfillmentContext.AvailabilityAndPriceDate, StartingIndex = (param.Page - 1) * SearchConfiguration.MaxItemsPerPage, // The starting index is zero-based. SortBy = param.SortBy, SortDirection = param.SortDirection, Page = param.Page, BaseUrl = param.BaseUrl, CultureInfo = ComposerContext.CultureInfo, Scope = ComposerContext.Scope, AutoCorrect = SearchConfiguration.AutoCorrectSearchTerms, CategoryId = param.CategoryId, CategoryHasFacets = param.SelectedFacets.Any() }; List <SearchFilter> selectedCategories = await GetSelectedCategoriesAsync(param).ConfigureAwait(false); List <SearchFilter> selectedFacets = param.SelectedFacets; criteria.SelectedFacets.AddRange(selectedCategories); criteria.SelectedFacets.AddRange(selectedFacets); return(criteria); }
public ActionResult ProductEdit(int Id) { var model = this._ObjectService.GetById(Id); ProductViewModel Product = new ProductViewModel(); Product.Id = model.Id; Product.Name = model.Name; Product.ParentId = model.ParentId; Product.Sort = model.Sort; Product.Unit = model.G_Name.Unit; Product.Image = model.G_Name.C_File.FileName; CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.ParentId = -1; SearchCriteria.Type = (int)CommonEnum.TypeOfDbObject.Classification; var attrsTypes = this._ObjectService.SearchCategory(SearchCriteria).Item1; var typelist = (from m in attrsTypes select new SelectListItem { Text = m.Name, Value = m.Id.ToString() }).ToList(); ViewBag.shopType = typelist; return(View(Product)); }
protected virtual IList <IFilter> GetFilters(CategorySearchCriteria criteria) { var result = new List <IFilter>(); if (!string.IsNullOrEmpty(criteria.SearchPhrase)) { var parseResult = _searchPhraseParser.Parse(criteria.SearchPhrase); criteria.SearchPhrase = parseResult.SearchPhrase; result.AddRange(parseResult.Filters); } if (criteria.ObjectIds != null) { result.Add(new IdsFilter { Values = criteria.ObjectIds }); } if (!string.IsNullOrEmpty(criteria.CatalogId)) { result.Add(FiltersHelper.CreateTermFilter("catalog", criteria.CatalogId.ToLowerInvariant())); } result.Add(FiltersHelper.CreateOutlineFilter(criteria)); var terms = criteria.GetTerms(); result.AddRange(terms.Select(term => FiltersHelper.CreateTermFilter(term.Key, term.Values))); return(result); }
public void Can_index_category_demo_data_and_search_using_outline(string providerType) { var scope = "test"; var provider = GetSearchProvider(providerType, scope); provider.RemoveAll(scope, ""); var controller = GetSearchIndexController(provider); controller.RemoveIndex(scope, "category"); controller.BuildIndex(scope, "category", x => { return; }); // sleep for index to be commited Thread.Sleep(5000); // find all prodducts in the category var categoryCriteria = new CategorySearchCriteria() { }; categoryCriteria.Outlines.Add("4974648a41df4e6ea67ef2ad76d7bbd4/45d3fc9a913d4610a5c7d0470558*"); var response = provider.Search <DocumentDictionary>(scope, categoryCriteria); Assert.True(response.TotalCount > 0, string.Format("Didn't find any categories using {0} search", providerType)); }
protected virtual void AddCategoryFilters(CategorySearchCriteria criteria) { if (!criteria.Outlines.IsNullOrEmpty()) { var outlines = criteria.Outlines.Select(o => o.TrimEnd('/', '*').ToLowerInvariant()); criteria.Apply(CreateAttributeFilter("__outline", outlines)); } }
public ActionResult Add() { CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.ParentId = -1; ViewBag.CategoryList = _objectService.SearchCategory(SearchCriteria).Item1.OrderBy(m => m.Sort).ToList(); ViewBag.Hotare = _HotareaService.GetByParentId(1); return(View()); }
public async Task <ActionResult> SearchCategories(CategorySearchCriteria searchCriteria) { var retVal = await _catalogSearchService.SearchCategoriesAsync(searchCriteria); return(Json(new { Categories = retVal, MetaData = retVal.GetMetaData() })); }
/// <summary> /// Search categories by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public virtual IPagedList <Category> SearchCategories(CategorySearchCriteria criteria) { var workContext = _workContextFactory(); criteria = criteria.Clone(); var searchCriteria = criteria.ToCategorySearchDto(workContext); var categories = _searchApi.SearchApiModule.SearchCategories(workContext.CurrentStore.Id, searchCriteria).Categories.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).ToList(); //API temporary does not support paginating request to categories (that's uses PagedList with superset) return(new PagedList <Category>(categories, criteria.PageNumber, criteria.PageSize)); }
/// <summary> /// Async search categories by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public virtual async Task <IPagedList <Category> > SearchCategoriesAsync(CategorySearchCriteria criteria) { var workContext = _workContextFactory(); criteria = criteria.Clone(); var searchCriteria = criteria.ToCategorySearchDto(workContext); var result = await _searchApi.SearchApiModule.SearchCategoriesAsync(workContext.CurrentStore.Id, searchCriteria); //API temporary does not support paginating request to categories (that's uses PagedList with superset instead StaticPagedList) return(new PagedList <Category>(result.Categories.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize)); }
private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext) { criteria = criteria.Clone(); var searchCriteria = criteria.ToCategorySearchDto(workContext); var result = await _searchApi.SearchApiModule.SearchCategoriesAsync(workContext.CurrentStore.Id, searchCriteria); var retVal = new PagedList <Category>(result.Categories.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize); //Set lazy loading for child categories SetChildCategoriesLazyLoading(retVal.ToArray()); return(retVal); }
/// <summary> /// Try to find (create if not) categories for products with Category.Path /// </summary> private async Task SaveCategoryTree(Catalog catalog, IEnumerable <CsvProduct> csvProducts, ExportImportProgressInfo progressInfo, Action <ExportImportProgressInfo> progressCallback) { var cachedCategoryMap = new Dictionary <string, Category>(); var outline = new StringBuilder(); foreach (var csvProduct in csvProducts.Where(x => x.Category != null && !string.IsNullOrEmpty(x.Category.Path))) { outline.Clear(); var productCategoryNames = csvProduct.Category.Path.Split(_categoryDelimiters); string parentCategoryId = null; foreach (var categoryName in productCategoryNames) { outline.Append($"\\{categoryName}"); Category category; if (!cachedCategoryMap.TryGetValue(outline.ToString(), out category)) { var searchCriteria = new CategorySearchCriteria { CatalogId = catalog.Id, CategoryId = parentCategoryId, SearchOnlyInRoot = parentCategoryId == null, Keyword = categoryName }; category = (await _categorySearchService.SearchCategoriesAsync(searchCriteria)).Results.FirstOrDefault(); } if (category == null) { var code = categoryName.GenerateSlug(); if (string.IsNullOrEmpty(code)) { code = Guid.NewGuid().ToString("N"); } category = new Category() { Name = categoryName, Code = code, CatalogId = catalog.Id, ParentId = parentCategoryId }; await _categoryService.SaveChangesAsync(new[] { category }); //Raise notification each notifyCategorySizeLimit category var count = progressInfo.ProcessedCount; progressInfo.Description = $"Creating categories: {++count} created"; progressCallback(progressInfo); } csvProduct.CategoryId = category.Id; csvProduct.Category = category; parentCategoryId = category.Id; cachedCategoryMap[outline.ToString()] = category; } } }
public async Task <ActionResult> SearchCategories([FromBody] CategorySearchCriteria searchCriteria) { var retVal = await _catalogService.SearchCategoriesAsync(searchCriteria); foreach (var category in retVal) { category.Url = base.UrlBuilder.ToAppAbsolute(category.Url); } return(Json(new { Categories = retVal, MetaData = retVal.GetMetaData() })); }
protected virtual IList <SortInfo> BuildSortExpression(CategorySearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = nameof(CategoryEntity.Name) } }; } return(sortInfos); }
protected virtual QueryContainer GetCategoryQuery <T>(CategorySearchCriteria criteria) where T : class { QueryContainer result = null; if (criteria != null) { if (criteria.Outlines != null && criteria.Outlines.Count > 0) { result = CreateQuery("__outline", criteria.Outlines); } } return(result); }
public JsonResult GetNodelist(int id) { CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.Type = (int)CommonEnum.TypeOfDbObject.Classification; SearchCriteria.ParentId = id; var attrsTypes = _ObjectService.SearchCategory(SearchCriteria).Item1; var typelist = (from m in attrsTypes select new SelectListItem { Text = m.Name, Value = m.Id.ToString() }).ToList(); return(Json(typelist, JsonRequestBehavior.DenyGet)); }
public void Can_index_category_demo_data_and_search_using_outline(string providerType) { var provider = GetSearchProvider(providerType, _scope); RebuildIndex(provider, CategorySearchCriteria.DocType); // find all products in the category var criteria = new CategorySearchCriteria { Outlines = new[] { "4974648a41df4e6ea67ef2ad76d7bbd4" }, }; var searchResults = provider.Search <DocumentDictionary>(_scope, criteria); Assert.True(searchResults.TotalCount > 0, $"Didn't find any categories using {providerType} provider"); }
public ActionResult list(int id = 0, int Parentid = 0) { CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.ParentId = Parentid; SearchCriteria.Id = id; if (id > 0 || Parentid > 0) { ViewBag.GoodsList = _objectService.SearchCategory(SearchCriteria).Item1.FirstOrDefault(); } CategorySearchCriteria Criteria = new CategorySearchCriteria(); Criteria.ParentId = -1; ViewBag.CategoryList = _objectService.SearchCategory(Criteria).Item1.OrderBy(m => m.Sort).ToList(); return(View()); }
public virtual catalogDto.CategorySearchCriteria ToCategorySearchCriteriaDto(CategorySearchCriteria criteria, WorkContext workContext) { var result = new catalogDto.CategorySearchCriteria { SearchPhrase = criteria.Keyword, LanguageCode = criteria.Language?.CultureName ?? workContext.CurrentLanguage.CultureName, StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, Outline = criteria.Outline, Sort = criteria.SortBy, Skip = criteria.Start, Take = criteria.PageSize, ResponseGroup = ((int)criteria.ResponseGroup).ToString(), }; return(result); }
private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext) { criteria = criteria.Clone(); var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext); var result = await _catalogModuleApi.CatalogModuleSearch.SearchCategoriesAsync(searchCriteria); var retVal = new PagedList <Category>(new List <Category>(), 1, 1); if (result.Items != null) { retVal = new PagedList <Category>(result.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize); } //Set lazy loading for child categories SetChildCategoriesLazyLoading(retVal.ToArray()); return(retVal); }
public ActionResult ProductList() { CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.PageIndex = 1; string txtName = Request.Params["txtName"] == null ? "" : Request.Params["txtName"]; if (!string.IsNullOrEmpty(txtName)) { ViewBag.txtName = txtName; } SearchCriteria.Name = txtName; SearchCriteria.Type = (int)CommonEnum.TypeOfDbObject.Product; var model = _ObjectService.SearchCategory(SearchCriteria); return(View(model)); }
protected virtual IList <SortingField> GetSorting(CategorySearchCriteria criteria) { var result = new List <SortingField>(); //For sorting by relevance have to keep sortInfo clear var needClearSortInfo = false; var priorityFields = criteria.GetPriorityFields(); foreach (var sortInfo in criteria.SortInfos) { var fieldName = sortInfo.SortColumn.ToLowerInvariant(); var isDescending = sortInfo.SortDirection == SortDirection.Descending; switch (fieldName) { case "relevance": needClearSortInfo = true; break; case "priority": result.AddRange(priorityFields.Select(priorityField => new SortingField(priorityField, isDescending))); break; case "name": case "title": result.Add(new SortingField("name", isDescending)); break; default: result.Add(new SortingField(fieldName, isDescending)); break; } } if (!result.Any()) { result.AddRange(priorityFields.Select(priorityField => new SortingField(priorityField, true))); result.Add(new SortingField("__sort")); } if (needClearSortInfo) { result.Clear(); } return(result); }
public virtual searchDto.CategorySearch ToCategorySearchDto(CategorySearchCriteria criteria, WorkContext workContext) { var result = new searchDto.CategorySearch() { Skip = criteria.Start, Take = criteria.PageSize, Outline = criteria.Outline, ResponseGroup = ((int)criteria.ResponseGroup).ToString() }; if (criteria.SortBy != null) { result.Sort = new string[] { criteria.SortBy } } ; return(result); }
public ActionResult AddPost(ProductViewModel model) { C_Object Cmodel = new C_Object(); Cmodel.Name = model.Name; Cmodel.ParentId = model.ParentId; Cmodel.Sort = model.Sort; Cmodel.Creater = UserId; Cmodel.CreateTime = DateTime.Now; Cmodel.LastModifyTime = DateTime.Now; Cmodel.LastModifyUser = UserId; Cmodel.Status = 0; Cmodel.Type = (int)CommonEnum.TypeOfDbObject.Product; Cmodel.IsDelete = false; this._ObjectService.Insert(Cmodel); C_File imgmodel = new C_File(); imgmodel.FileName = model.Image; this._ObjectService.InsertImage(imgmodel); G_Name Gmodel = new G_Name(); Gmodel.Id = Cmodel.Id; Gmodel.Unit = model.Unit; Gmodel.Image = imgmodel.Id; this._GoodsService.InsertUnit(Gmodel); CategorySearchCriteria SearchCriteria = new CategorySearchCriteria(); SearchCriteria.ParentId = -1; SearchCriteria.Type = (int)CommonEnum.TypeOfDbObject.Classification; var attrsTypes = this._ObjectService.SearchCategory(SearchCriteria).Item1; var typelist = (from m in attrsTypes select new SelectListItem { Text = m.Name, Value = m.Id.ToString() }).ToList(); ViewBag.shopType = typelist; ViewBag.msg = "添加成功"; return(View(model)); }
public static catalogDto.CategorySearchCriteria ToCategorySearchCriteriaDto(this CategorySearchCriteria criteria, WorkContext workContext) { var result = new catalogDto.CategorySearchCriteria { SearchPhrase = criteria.Keyword, LanguageCode = criteria.Language?.CultureName ?? workContext.CurrentLanguage.CultureName, StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, Outline = criteria.Outline, UserGroups = workContext.CurrentUser?.Contact?.UserGroups ?? new List <string>(), // null value disables filtering by user groups Sort = criteria.SortBy, Skip = criteria.Start, Take = criteria.PageSize, ResponseGroup = ((int)criteria.ResponseGroup).ToString(), IsFuzzySearch = criteria.IsFuzzySearch, }; return(result); }
public async Task <CategorySearchResult> SearchCategoriesAsync(CategorySearchCriteria criteria) { var result = AbstractTypeFactory <CategorySearchResult> .TryCreateInstance(); using (var repository = _catalogRepositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var query = repository.Categories; if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword)); } if (!string.IsNullOrEmpty(criteria.CatalogId)) { query = query.Where(x => x.CatalogId == criteria.CatalogId); } if (!string.IsNullOrEmpty(criteria.CategoryId)) { query = query.Where(x => x.ParentCategoryId == criteria.CategoryId); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "Name" } }; } query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var ids = await query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToListAsync(); var categories = await _categoryService.GetByIdsAsync(ids.ToArray(), criteria.ResponseGroup); result.Results = categories.OrderBy(x => ids.IndexOf(x.Id)).ToList(); } } return(result); }