public CatalogItemSearchResults SearchItems(string scope, CatalogItemSearchCriteria criteria) { var results = _searchService.Search(scope, criteria) as SearchResults; var items = results.GetKeyAndOutlineFieldValueMap <string>(); var r = new CatalogItemSearchResults(criteria, items, results); return(r); }
private IEnumerable <moduleModel.CatalogProduct> Search(CatalogIndexedSearchCriteria criteria, out CatalogItemSearchResults results, moduleModel.ItemResponseGroup responseGroup) { var items = new List <moduleModel.CatalogProduct>(); var itemsOrderedList = new List <string>(); var foundItemCount = 0; var dbItemCount = 0; var searchRetry = 0; //var myCriteria = criteria.Clone(); var myCriteria = criteria; do { // Search using criteria, it will only return IDs of the items var scope = _searchConnection.Scope; var searchResults = _searchProvider.Search(scope, criteria) as SearchResults; var itemKeyValues = searchResults.GetKeyAndOutlineFieldValueMap <string>(); results = new CatalogItemSearchResults(myCriteria, itemKeyValues, searchResults); searchRetry++; if (results.Items == null) { continue; } //Get only new found itemIds var uniqueKeys = results.Items.Keys.Except(itemsOrderedList).ToArray(); foundItemCount = uniqueKeys.Length; if (!results.Items.Any()) { continue; } itemsOrderedList.AddRange(uniqueKeys); // Now load items from repository var currentItems = _itemService.GetByIds(uniqueKeys.ToArray(), responseGroup, criteria.Catalog); var orderedList = currentItems.OrderBy(i => itemsOrderedList.IndexOf(i.Id)); items.AddRange(orderedList); dbItemCount = currentItems.Length; //If some items where removed and search is out of sync try getting extra items if (foundItemCount > dbItemCount) { //Retrieve more items to fill missing gap myCriteria.RecordsToRetrieve += (foundItemCount - dbItemCount); } }while (foundItemCount > dbItemCount && results.Items.Any() && searchRetry <= 3 && (myCriteria.RecordsToRetrieve + myCriteria.StartingRecord) < results.TotalCount); return(items); }
public VirtoCommerce.Foundation.Catalogs.Search.CatalogItemSearchResults SearchItems(string scope, VirtoCommerce.Foundation.Catalogs.Search.CatalogItemSearchCriteria criteria) { var resultDocumentSet = new ResultDocumentSet(); resultDocumentSet.TotalCount = ProductList.Count(); resultDocumentSet.Documents = new ResultDocument[] { }; var searchResult = new SearchResults(criteria, new ResultDocumentSet[] { resultDocumentSet }); var items = ProductList.Skip(criteria.StartingRecord).Take(criteria.RecordsToRetrieve).ToArray(); var result = new CatalogItemSearchResults(criteria, null, searchResult); return(result); }
private List <Item> Search(CatalogItemSearchCriteria criteria, bool cacheResults, out CatalogItemSearchResults results) { var items = new List <Item>(); var itemsOrderedList = new List <string>(); int foundItemCount; int dbItemCount = 0; int searchRetry = 0; var myCriteria = criteria.Clone(); do { // Search using criteria, it will only return IDs of the items results = _catalogClient.SearchItems(myCriteria, cacheResults); searchRetry++; //Get only new found itemIds var uniqueKeys = results.Items.Keys.Except(itemsOrderedList).ToArray(); foundItemCount = uniqueKeys.Length; if (!results.Items.Any()) { continue; } itemsOrderedList.AddRange(uniqueKeys); // Now load items from repository var currentItems = _catalogClient.GetItems(uniqueKeys.ToArray(), cacheResults, ItemResponseGroups.ItemAssets | ItemResponseGroups.ItemProperties | ItemResponseGroups.ItemEditorialReviews); items.AddRange(currentItems.OrderBy(i => itemsOrderedList.IndexOf(i.ItemId))); dbItemCount = currentItems.Length; //If some items where removed and search is out of sync try getting extra items if (foundItemCount > dbItemCount) { //Retrieve more items to fill missing gap myCriteria.RecordsToRetrieve += (foundItemCount - dbItemCount); } } while (foundItemCount > dbItemCount && results.Items.Any() && searchRetry <= 3 && (myCriteria.RecordsToRetrieve + myCriteria.StartingRecord) < results.TotalCount); return(items); }