public ActionResult ManageSearchedTerms(int? pageIndex = 1, int pageSize = 20) { CountService countService = new CountService(TenantTypeIds.Instance().Search()); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search()); IEnumerable<ISearcher> searchers = SearcherFactory.GetDisplaySearchers(); #region 搜索条件 int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount()); string countTypeNday = countService.GetStageCountType(CountTypes.Instance().SearchCount(), stageCountDays); string countTypeAll = CountTypes.Instance().SearchCount(); pageResourceManager.InsertTitlePart("管理搜索热词"); string term = Request.QueryString.GetString("term", string.Empty).Trim(); bool isRealtime = false; DateTime? startDate = null; DateTime? endDate = null; if (Request.QueryString.Get<DateTime>("startdate") != DateTime.MinValue) startDate = Request.QueryString.Get<DateTime>("startDate"); if (Request.QueryString.Get<DateTime>("enddate") != DateTime.MinValue) endDate = Request.QueryString.Get<DateTime>("endDate"); if (startDate.HasValue && endDate.HasValue && startDate.Value > endDate.Value) { DateTime? changDate = startDate; startDate = endDate; endDate = changDate; } if (endDate.HasValue) endDate = endDate.Value; #endregion #region 下拉列表 string searchTypeCode = Request.QueryString.GetString("searchTypeCode", string.Empty); Dictionary<string, string> searchTypeDic = new Dictionary<string, string>(); searchTypeDic[SearcherFactory.GlobalSearchCode] = SearcherFactory.GlobalSearchName; foreach (var searcher in searchers) { searchTypeDic[searcher.Code] = searcher.Name; } SelectList selectList = new SelectList(searchTypeDic.Select(n => new { text = n.Value, value = n.Key }), "value", "text", searchTypeCode); ViewData["searchTypeCode"] = selectList; #endregion if (string.IsNullOrEmpty(searchTypeCode)) { isRealtime = true; } ViewData["searchTypeDic"] = searchTypeDic; #region Count IEnumerable<SearchedTerm> manuals = null; if (pageIndex == 1) manuals = termService.GetManuals(searchTypeCode); Dictionary<long, int> countTypeNdayDic = new Dictionary<long, int>(); Dictionary<long, int> countTypeAllDic = new Dictionary<long, int>(); if (manuals != null) { if (!string.IsNullOrEmpty(term)) manuals = manuals.Where(n => Regex.IsMatch(n.Term, "^" + term.Trim())); if (!string.IsNullOrEmpty(searchTypeCode)) manuals = manuals.Where(n => n.SearchTypeCode == searchTypeCode); if (startDate != null) manuals = manuals.Where(n => n.DateCreated >= startDate); if (endDate != null) manuals = manuals.Where(n => n.DateCreated <= endDate); foreach (var item in manuals) { countTypeNdayDic[item.Id] = countService.Get(countTypeNday, item.Id); countTypeAllDic[item.Id] = countService.Get(countTypeAll, item.Id); } } ViewData["manuals"] = manuals; PagingDataSet<SearchedTerm> searchedTerms = termService.Gets(searchTypeCode, term, startDate, endDate, isRealtime, pageSize, pageIndex ?? 1); foreach (var item in searchedTerms) { countTypeNdayDic[item.Id] = countService.Get(countTypeNday, item.Id); countTypeAllDic[item.Id] = countService.Get(countTypeAll, item.Id); } ViewData["countTypeNdayDic"] = countTypeNdayDic; ViewData["countTypeAllDic"] = countTypeAllDic; #endregion return View(searchedTerms); }