/// <summary> /// /// </summary> /// <param name="query"></param> /// <returns>Sorted list of ArticleItemProxies based on query</returns> public List <ArticleItemWrapper> RunSearch(VwbQuery query) { // var param = new ArticleSearchParam(); //param.IncludeSidebarArticles(); List <ArticleItemWrapper> articles; using (new Sitecore.SecurityModel.SecurityDisabler()) { string searchPageId = Constants.VWBSearchPageId; string hostName = Factory.GetSiteInfo("website")?.HostName ?? WebUtil.GetHostName(); string url = string.Format("{0}://{1}/api/informasearch?pId={2}&sortBy=plannedpublishdate&sortOrder=desc", HttpContext.Current.Request.Url.Scheme, hostName, searchPageId); if (query.InProgressValue) { url += "&inprogress=1"; } DateTime startDate = (query.StartDate != null) ? query.StartDate.Value : DateTime.Now.AddDays(-1).Date;//From the begining of the day before DateTime endDate = (query.EndDate != null) ? query.EndDate.Value : DateTime.Now.Date.AddDays(31).AddSeconds(-1);//till the end of 30 days ahead url += "&plannedpublishdate=" + startDate.ToString("MM/dd/yyyy"); url += ";" + endDate.ToString("MM/dd/yyyy"); if (string.IsNullOrEmpty(query.PublicationCodes) == false) { url += "&SearchPublicationTitle=" + query.PublicationCodes; } var client = new WebClient(); var content = client.DownloadString(url); var results = JsonConvert.DeserializeObject <SearchResults>(content); var resultItems = new List <ArticleItem>(); Database masterDb = Factory.GetDatabase("master"); foreach (var searchResult in results.results) { var theItem = (ArticleItem)masterDb.GetItem(searchResult.ItemId); if (theItem == null) { continue; } //Manually filtering for time IArticle article = theItem.InnerItem.GlassCast <IArticle>(inferType: true); if (article.Planned_Publish_Date.Ticks >= startDate.Ticks && article.Planned_Publish_Date.Ticks <= endDate.Ticks) { resultItems.Add(theItem); } } articles = ArticleItemWrapper.GetArticleItemProxies(resultItems).ToList(); } if (query.SortColumnKey != null && ColumnFactory.GetColumn(query.SortColumnKey) != null) { articles.Sort(ColumnFactory.GetColumn(query.SortColumnKey)); } if (query.SortColumnKey == ColumnFactory.GetArticleNumberColumn().Key()) { articles.Sort(ColumnFactory.GetArticleNumberColumn()); } if (query.SortColumnKey == ColumnFactory.GetTitleColumn().Key()) { articles.Sort(ColumnFactory.GetTitleColumn()); } if (query.Descending) { articles.Reverse(); } if (query.NumResultsValue != null) { return(articles.GetRange(0, Math.Min(articles.Count, (int)query.NumResultsValue))); } return(articles); }