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 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; }