public IHttpActionResult Search(SearchCriteria criteria) { var coreModelCriteria = criteria.ToCoreModel(); ApplyRestrictionsForCurrentUser(coreModelCriteria); var serviceResult = _searchService.Search(coreModelCriteria); return(Ok(serviceResult.ToWebModel(_blobUrlResolver))); }
public IHttpActionResult ListItemsSearch(webModel.SearchCriteria criteria) { var coreModelCriteria = criteria.ToCoreModel(); ApplyRestrictionsForCurrentUser(coreModelCriteria); coreModelCriteria.WithHidden = true; //Need search in children categories if user specify keyword if (!string.IsNullOrEmpty(coreModelCriteria.Keyword)) { coreModelCriteria.SearchInChildren = true; coreModelCriteria.SearchInVariations = true; } var retVal = new webModel.ListEntrySearchResult(); int categorySkip = 0; int categoryTake = 0; //Because products and categories represent in search result as two separated collections for handle paging request //we should join two resulting collection artificially //search categories if ((coreModelCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithCategories) == coreModel.SearchResponseGroup.WithCategories) { coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithProducts; var categoriesSearchResult = _searchService.Search(coreModelCriteria); var categoriesTotalCount = categoriesSearchResult.Categories.Count(); categorySkip = Math.Min(categoriesTotalCount, coreModelCriteria.Skip); categoryTake = Math.Min(coreModelCriteria.Take, Math.Max(0, categoriesTotalCount - coreModelCriteria.Skip)); var categories = categoriesSearchResult.Categories.Skip(categorySkip).Take(categoryTake).Select(x => new webModel.ListEntryCategory(x.ToWebModel(_blobUrlResolver))).ToList(); retVal.TotalCount = categoriesTotalCount; retVal.ListEntries.AddRange(categories); coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup | coreModel.SearchResponseGroup.WithProducts; } //search products if ((coreModelCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithProducts) == coreModel.SearchResponseGroup.WithProducts) { coreModelCriteria.ResponseGroup = coreModelCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithCategories; coreModelCriteria.Skip = coreModelCriteria.Skip - categorySkip; coreModelCriteria.Take = coreModelCriteria.Take - categoryTake; var productsSearchResult = _searchService.Search(coreModelCriteria); var products = productsSearchResult.Products.Select(x => new webModel.ListEntryProduct(x.ToWebModel(_blobUrlResolver))); retVal.TotalCount += productsSearchResult.ProductsTotalCount; retVal.ListEntries.AddRange(products); } return(Ok(retVal)); }
private webModel.ListEntrySearchResult SearchListEntries(webModel.SearchCriteria criteria) { var coreModelCriteria = criteria.ToCoreModel(); ApplyRestrictionsForCurrentUser(coreModelCriteria); coreModelCriteria.WithHidden = true; // need search in children categories if user specify keyword if (!string.IsNullOrEmpty(coreModelCriteria.Keyword)) { coreModelCriteria.SearchInChildren = true; coreModelCriteria.SearchInVariations = true; } return(_listEntrySearchService.Search(coreModelCriteria)); }
public IHttpActionResult ListItemsSearch(webModel.SearchCriteria criteria) { var coreModelCriteria = criteria.ToCoreModel(); ApplyRestrictionsForCurrentUser(coreModelCriteria); coreModelCriteria.WithHidden = true; // need search in children categories if user specify keyword if (!string.IsNullOrEmpty(coreModelCriteria.Keyword)) { coreModelCriteria.SearchInChildren = true; coreModelCriteria.SearchInVariations = true; } var result = _listEntrySearchService.Search(coreModelCriteria); return(Ok(result)); }