public ActionResult GetSearchArea(float minX, float minY, float maxX, float maxY, int page = 1, int category = 0, int price = 0) { var model = new QuerySource(); var result = new List<LinkItem>(); QueryTerm query = new QueryTerm(); query.MinX = minX; query.MinY = minY; query.MaxX = maxX; query.MaxY = maxY; if (category != 0) { query.MediaCode = category; query.MediaMaxCode = Utilities.GetMaxCode(category); } if (price != 0) { query.Price = price; } var pageSize = 10; int totalHits = 0; SearchFilter sf = new SearchFilter(); sf.PageSize = pageSize; sf.Skip = (page - 1) * pageSize; sf.Take = pageSize; sf.SortProperty = SortProperty.Published; sf.SortDirection = SortDirection.Descending; result = OutDoorLuceneService.Search(query, sf, out totalHits); model.Items = result; model.TotalCount = totalHits; model.CurrentPage = page; model.PageSize = pageSize; return Json(model, JsonRequestBehavior.AllowGet); }
private static Query ParseQuery(QueryTerm queryTerm, SearchFilter searchFilter) { var combineQuery = new BooleanQuery(); #region 关键字查询构建 if (!String.IsNullOrWhiteSpace(searchFilter.SearchTerm)) { var fields = new[] { OutDoorIndexFields.Title, OutDoorIndexFields.Description, OutDoorIndexFields.AreaCate, OutDoorIndexFields.IndustryCate, OutDoorIndexFields.CrowdCate, OutDoorIndexFields.PurposeCate, OutDoorIndexFields.MediaCateName, OutDoorIndexFields.CityCateName, OutDoorIndexFields.FormatName, OutDoorIndexFields.PeriodName, OutDoorIndexFields.OwnerName }; var analyzer = new PanGuAnalyzer(); //var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion); var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields, analyzer); var query = queryParser.Parse(searchFilter.SearchTerm); //conjuction 一起选择 var conjuctionQuery = new BooleanQuery(); conjuctionQuery.Boost = 2.0f; //disjunction 分离 var disjunctionQuery = new BooleanQuery(); disjunctionQuery.Boost = 0.1f; //wildCard 通配符 var wildCardQuery = new BooleanQuery(); wildCardQuery.Boost = 0.5f; var escapedSearchTerm = Escape(searchFilter.SearchTerm); var exactIdQuery = new TermQuery(new Term(OutDoorIndexFields.Title, escapedSearchTerm)); exactIdQuery.Boost = 2.5f; var wildCardIdQuery = new WildcardQuery(new Term(OutDoorIndexFields.Title, "*" + escapedSearchTerm + "*")); foreach (var term in GetSearchTerms(searchFilter.SearchTerm)) { var termQuery = queryParser.Parse(term); conjuctionQuery.Add(termQuery, Occur.MUST); disjunctionQuery.Add(termQuery, Occur.SHOULD); foreach (var field in fields) { var wildCardTermQuery = new WildcardQuery(new Term(field, term + "*")); wildCardTermQuery.Boost = 0.7f; wildCardQuery.Add(wildCardTermQuery, Occur.SHOULD); } } //关键查询 var keywordsQuery = conjuctionQuery.Combine(new Query[] { exactIdQuery, wildCardIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery }); combineQuery.Add(keywordsQuery, Occur.MUST); } #endregion #region 指定媒体ID查询 if (queryTerm.MediaID != 0) { var mediaIdQuery = new TermQuery(new Term(OutDoorIndexFields.ID, queryTerm.MediaID.ToString())); combineQuery.Add(mediaIdQuery, Occur.MUST); } #endregion #region 用户状态 var memberStatusQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.MemberStatus, (int)MemberStatus.CompanyAuth, 99, true, true); combineQuery.Add(memberStatusQuery, Occur.MUST); #endregion #region 审核状态查询构建 var verifyStatus = NumericRangeQuery.NewIntRange(OutDoorIndexFields.Status, (int)OutDoorStatus.ShowOnline, 99, true, true); combineQuery.Add(verifyStatus, Occur.MUST); #endregion #region 指定用户ID查询 if (queryTerm.MemberID != 0) { var memberIdQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.MemberID, queryTerm.MemberID, queryTerm.MemberID, true, true); combineQuery.Add(memberIdQuery, Occur.MUST); } #endregion #region 城市查询 if (queryTerm.City != 0) { var cityQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.CityCateCode, queryTerm.CityCateCode, queryTerm.CityMaxCode, true, true); combineQuery.Add(cityQuery, Occur.MUST); } #endregion #region 认证状态 if (queryTerm.AuthStatus != 0) { var authStatusQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.AuthStatus, queryTerm.AuthStatus, queryTerm.AuthStatus, true, true); combineQuery.Add(authStatusQuery, Occur.MUST); } #endregion #region 经纬度搜索 if (queryTerm.MinX != 0) { var latQuery = NumericRangeQuery.NewDoubleRange(OutDoorIndexFields.Lat, queryTerm.MinX, queryTerm.MaxX, true, true); var lngQuery = NumericRangeQuery.NewDoubleRange(OutDoorIndexFields.Lng, queryTerm.MinY, queryTerm.MaxY, true, true); combineQuery.Add(latQuery, Occur.MUST); combineQuery.Add(lngQuery, Occur.MUST); } #endregion #region 媒体类别查询 if (queryTerm.MediaCode != 0) { var mediaCodeQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.MediaCateCode, queryTerm.MediaCateCode, queryTerm.MediaMaxCode, true, true); combineQuery.Add(mediaCodeQuery, Occur.MUST); } #endregion #region 媒体表现形式查询 if (queryTerm.FormatCode != 0) { var FormatCodeCodeQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.FormatCode, queryTerm.FormatCode, queryTerm.FormatCode, true, true); combineQuery.Add(FormatCodeCodeQuery, Occur.MUST); } #endregion #region 媒体所有权查询 //if (queryTerm.OwnerCode != 0) //{ // var OwnerCodeCodeQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.OwnerCode, // queryTerm.OwnerCode, queryTerm.OwnerCode, true, true); // combineQuery.Add(OwnerCodeCodeQuery, Occur.MUST); //} #endregion #region 媒体购买周期查询 if (queryTerm.PeriodCode != 0) { var PeriodCodeCodeQuery = NumericRangeQuery.NewIntRange(OutDoorIndexFields.PeriodCode, queryTerm.PeriodCode, queryTerm.PeriodCode, true, true); combineQuery.Add(PeriodCodeCodeQuery, Occur.MUST); } #endregion #region 媒体价格区间查询 if (queryTerm.Price != 0) { var rangeValue = EnumHelper.GetPriceValue(queryTerm.Price); var PriceQuery = NumericRangeQuery.NewDoubleRange(OutDoorIndexFields.Price, Convert.ToDouble(rangeValue.Min), Convert.ToDouble(rangeValue.Max), true, true); combineQuery.Add(PriceQuery, Occur.MUST); } #endregion #region 媒体档期查询 if (queryTerm.DeadLine != 0) { var minValue = (DateTime.Now.AddYears(-10)).Ticks; var maxValue = (new DateTime(DateTime.Now.Year, queryTerm.DeadLine, 1)).Ticks; var DeadLineQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.DeadLine, Convert.ToInt64(minValue), Convert.ToInt64(maxValue), true, true); combineQuery.Add(DeadLineQuery, Occur.MUST); } #endregion #region 媒体档期时间查询 if (!string.IsNullOrEmpty(queryTerm.Dq)) { var minValue = (DateTime.Now.AddYears(-10)).Ticks; var maxValue = Convert.ToDateTime(queryTerm.Dq).Ticks; var DqQuery = NumericRangeQuery.NewLongRange(OutDoorIndexFields.DeadLine, Convert.ToInt64(minValue), Convert.ToInt64(maxValue), true, true); combineQuery.Add(DqQuery, Occur.MUST); } #endregion return combineQuery; }
private void SetCompanyIndexCategories(List<CompanyCategoryViewModel> categories, int ID) { int PageSize = 4; foreach (var category in categories) { var codeId = Convert.ToInt32(category.Code); var cate = MediaCateService.Find(codeId); var maxCode = Utilities.GetMaxCode(cate.Code, cate.Level); QueryTerm queryTerm = new QueryTerm() { MemberID = ID, MediaCode = codeId, MediaCateCode = cate.Code, MediaMaxCode = maxCode, Page = 1 }; var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize); searchFilter.Take = 4; int totalHits = 0; var query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits); category.Products = query.Select(x => new CompanyProductViewMidel() { AddTime = x.AddTime, MediaCateName = x.MediaCateName, CityCateName = x.CityCateName, DeadLine = x.DeadLine, Description = x.Description, FocusImgUrl = x.FocusImgUrl, ID = x.ID, Name = x.Name, Price = x.Price, FormatName = x.FormatName, PeriodName = x.PeriodName }).ToList(); } }
public List<LinkItem> Search(QueryTerm queryTerm, SearchFilter searchFilter, out int totalHits) { if (!Directory.Exists(LuceneCommon.IndexOutDoorDirectory)) { totalHits = 0; return new List<LinkItem>(); } SortField sortField = GetSortField(searchFilter); var sortFieldArry = new List<SortField>(){ new SortField(OutDoorIndexFields.SuggestStatus, SortField.INT, reverse: true) }; sortFieldArry.Add(sortField); int numRecords = searchFilter.Skip + searchFilter.Take; using (var directory = new SimpleFSDirectory(new DirectoryInfo(LuceneCommon.IndexOutDoorDirectory))) { var searcher = new IndexSearcher(directory, readOnly: true); var query = ParseQuery(queryTerm, searchFilter); //var termQuery = new TermQuery(new Term(OutDoorIndexFields.ID, "1")); var results = searcher.Search(query, filter: null, n: numRecords, sort: new Sort(sortFieldArry.ToArray())); var keys = results.ScoreDocs.Skip(searchFilter.Skip) .Select(c => GetMediaItem(searcher.Doc(c.Doc))) .ToList(); totalHits = results.TotalHits; searcher.Dispose(); return keys; } }
public ActionResult Index(int province = 1, int city = 0, int mediacode = 0, int formatcode = 0, int ownercode = 0, int periodcode = 0, int authstatus = 0, int deadline = 0, int price = 0, int order = 0, int descending = 0, int page = 1, string query = null, string dq = null) { if (city == 1) { city = 0; } //搜索条件 QueryTerm queryTerm = new QueryTerm() { Province = province, City = city, MediaCode = mediacode, FormatCode = formatcode, OwnerCode = ownercode, PeriodCode = periodcode, Page = page, AuthStatus = authstatus, DeadLine = deadline, Price = price, Order = order, Descending = descending, Query = query, Dq = dq }; if (!string.IsNullOrEmpty(queryTerm.Dq)) { if (queryTerm.Dq.Equals(DateTime.Now.ToString("yyyy-MM-dd"))) { queryTerm.Dq = null; } } CacheService.Clear(); if (queryTerm.City != 0) { var cityCate = CityCateService.Find(queryTerm.City); queryTerm.CityCateCode = cityCate.Code; queryTerm.CityMaxCode = Utilities.GetMaxCode(cityCate.Code, cityCate.Level); } if (queryTerm.MediaCode != 0) { var mediaCate = MediaCateService.Find(queryTerm.MediaCode); queryTerm.MediaCateCode = mediaCate.Code; queryTerm.MediaMaxCode = Utilities.GetMaxCode(mediaCate.Code, mediaCate.Level); } ViewBag.Search = GetSearch(queryTerm); ViewBag.PriceListFilter = GetPriceListFilter(queryTerm); ViewBag.DeadLineMonthFilter = GetDeadLineMonthFilter(queryTerm); ViewBag.DefaultOrderUrl = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = 0, descending = 0, page = 1, }); ViewBag.PriceOrderAscUrl = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = (int)SortProperty.Price, descending = (int)SortDirection.Ascending, page = 1 }); ViewBag.PriceOrderDescUrl = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = (int)SortProperty.Price, descending = (int)SortDirection.Descending, page = 1 }); ViewBag.NoAuthedUrl = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = 0, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }); ViewBag.AuthedUrl = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = 1, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }); ViewBag.Authed = queryTerm.AuthStatus == 1; ViewBag.Result = GetResult(queryTerm); ViewBag.Sort = GetSort(queryTerm); ViewBag.Query = queryTerm; return View(); }
private QuerySource GetCompanySources(int ID, int c, int page) { const int PageSize = 15; var model = new QuerySource(); var query = new List<LinkItem>(); int totalHits; QueryTerm queryTerm = new QueryTerm() { MemberID = ID, Page = page }; if (c != 0) { var cate = MediaCateService.Find(c); var maxCode = Utilities.GetMaxCode(cate.Code, cate.Level); queryTerm.MediaCode = c; queryTerm.MediaCateCode = cate.Code; queryTerm.MediaMaxCode = Utilities.GetMaxCode(cate.Code, cate.Level); } var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize); query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits); model.Items = query; model.TotalCount = totalHits; model.CurrentPage = queryTerm.Page; model.PageSize = PageSize; model.Querywords = string.IsNullOrEmpty(queryTerm.Query) ? "" : queryTerm.Query; return model; }
private QuerySource GetResult(QueryTerm queryTerm) { const int PageSize = 15; var model = new QuerySource(); var query = new List<LinkItem>(); int totalHits; Dictionary<string, string> cacheDic = CreateSearchDic("ResultList", queryTerm); Dictionary<string, string> countDic = CreateSearchDic("ResultCount", queryTerm); if (string.IsNullOrWhiteSpace(queryTerm.Dq)) { if (string.IsNullOrWhiteSpace(queryTerm.Query) && CacheService.Exists(cacheDic) && CacheService.Exists(countDic)) { query = CacheService.Get<List<LinkItem>>(cacheDic); totalHits = CacheService.GetInt32Value(countDic); } else { var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize); query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits); //query = OutDoorLuceneService.Search(out totalHits); if (string.IsNullOrWhiteSpace(queryTerm.Query)) { CacheService.Add<List<LinkItem>>(query, cacheDic, 10); CacheService.AddInt32Value(totalHits, countDic, 10); } } } else { var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize); query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits); } model.Items = query; model.TotalCount = totalHits; model.CurrentPage = queryTerm.Page; model.PageSize = PageSize; model.Querywords = string.IsNullOrEmpty(queryTerm.Query) ? "" : queryTerm.Query; return model; }
private List<LinkGroup> GetSearch(QueryTerm queryTerm) { List<LinkGroup> result = new List<LinkGroup>(); Dictionary<string, string> cacheDic = new Dictionary<string, string>(); cacheDic.Add(CacheService.ServiceName, "ListController"); cacheDic.Add(CacheService.ServiceMethod, "GetSearch"); cacheDic.Add("City", queryTerm.City.ToString()); cacheDic.Add("MediaCode", queryTerm.MediaCode.ToString()); cacheDic.Add("FormatCode", queryTerm.FormatCode.ToString()); cacheDic.Add("OwnerCode", queryTerm.OwnerCode.ToString()); cacheDic.Add("PeriodCode", queryTerm.PeriodCode.ToString()); if (CacheService.Exists(cacheDic)) { result = CacheService.Get<List<LinkGroup>>(cacheDic); return result; } #region CityGroup if (queryTerm.City != 0) { var city = CityCateService.Find(queryTerm.City); var prevCityGroup = new List<LinkGroup>(); GetPrevCityGroup(prevCityGroup, city, queryTerm); prevCityGroup.Reverse(); result.AddRange(prevCityGroup); GetNextCityGroup(result, city, queryTerm); } else { var city = CityCateService.Find(queryTerm.Province); GetNextCityGroup(result, city, queryTerm); } #endregion #region MediaCode if (queryTerm.MediaCode != 0) { var media = MediaCateService.Find(queryTerm.MediaCode); var prevMediaGroup = new List<LinkGroup>(); GetPrevMediaGroup(prevMediaGroup, media, queryTerm); prevMediaGroup.Reverse(); result.AddRange(prevMediaGroup); GetNextMediaGroup(result, media, queryTerm, false); } else { GetNextMediaGroup(result, null, queryTerm, true); } #endregion #region FormatCode LinkGroup formatGroup = new LinkGroup() { Group = new LinkItem() { Name = "媒体形式", Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = 0, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; formatGroup.Items = FormatCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = x.ID, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }), Selected = queryTerm.FormatCode == x.ID }).ToList(); result.Add(formatGroup); #endregion #region OwnerCode //LinkGroup ownerGroup = new LinkGroup() //{ // Group = new LinkItem() // { // Name = "代理类型", // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = 0, // periodcode = queryTerm.PeriodCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }) // } //}; //ownerGroup.Items = OwnerCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() //{ // ID = x.ID, // Name = x.CateName, // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = x.ID, // periodcode = queryTerm.PeriodCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }), // Selected = queryTerm.OwnerCode == x.ID //}).ToList(); //result.Add(ownerGroup); #endregion #region PeriodCode //LinkGroup periodGroup = new LinkGroup() //{ // Group = new LinkItem() // { // Name = "最短投放周期", // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = queryTerm.OwnerCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }) // } //}; //periodGroup.Items = PeriodCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() //{ // ID = x.ID, // Name = x.CateName, // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = queryTerm.OwnerCode, // periodcode = x.ID, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }), // Selected = queryTerm.PeriodCode == x.ID //}).ToList(); //result.Add(periodGroup); #endregion CacheService.Add<List<LinkGroup>>(result, cacheDic, 180); return result; }
private void GetPrevMediaGroup(List<LinkGroup> result, MediaCate media, QueryTerm queryTerm) { if (media.PID.HasValue) { var pMedia = MediaCateService.GetALL().Single(x => x.ID == media.PID); LinkGroup mediaGroup = new LinkGroup() { Group = new LinkItem() { Name = pMedia.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = pMedia.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var mediaList = MediaCateService.GetALL() .Where(x => x.PID == pMedia.ID).ToList(); var mediaSelectList = mediaList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = x.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (mediaSelectList.Any(x => x.ID == media.ID)) { mediaSelectList.Single(x => x.ID == media.ID).Selected = true; } mediaGroup.Items = mediaSelectList; result.Add(mediaGroup); GetPrevMediaGroup(result, pMedia, queryTerm); } else { LinkGroup mediaGroup = new LinkGroup() { Group = new LinkItem() { Name = "媒体分类", Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = 0, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var mediaList = MediaCateService.GetALL() .Where(x => x.PID.Equals(null)).ToList(); var mediaSelectList = mediaList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = x.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (mediaSelectList.Any(x => x.ID == media.ID)) { mediaSelectList.Single(x => x.ID == media.ID).Selected = true; } mediaGroup.Items = mediaSelectList; result.Add(mediaGroup); } }
private List<LinkItem> GetPriceListFilter(QueryTerm queryTerm) { List<LinkItem> result = new List<LinkItem>(); result = UIHelper.PriceList.Select(x => new LinkItem() { Name = x.Text, Selected = x.Value == queryTerm.Price.ToString(), Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = Convert.ToInt32(x.Value), order = queryTerm.Order, descending = queryTerm.Descending, page = 1, }) }).ToList(); return result; }
private void GetPrevCityGroup(List<LinkGroup> result, CityCate city, QueryTerm queryTerm) { var pCity = CityCateService.GetALL().Single(x => x.ID == city.PID); LinkGroup cityGroup = new LinkGroup() { Group = new LinkItem() { Name = !pCity.PID.HasValue ? "城市" : pCity.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = !pCity.PID.HasValue ? 0 : pCity.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var cityList = CityCateService.GetALL() .Where(x => x.PID == pCity.ID).ToList(); var citySelectList = cityList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = x.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (citySelectList.Any(x => x.ID == city.ID)) { citySelectList.Single(x => x.ID == city.ID).Selected = true; } cityGroup.Items = citySelectList; result.Add(cityGroup); if (pCity.PID.HasValue) { GetPrevCityGroup(result, pCity, queryTerm); } }
private void GetNextCityGroup(List<LinkGroup> result, CityCate city, QueryTerm queryTerm) { if (CityCateService.GetALL().Any(x => x.PID == city.ID)) { LinkGroup cityGroup = new LinkGroup() { Group = new LinkItem() { Name = city.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = city.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var cityList = CityCateService.GetALL() .Where(x => x.PID == city.ID).ToList(); var citySelectList = cityList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = x.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); cityGroup.Items = citySelectList; result.Add(cityGroup); } }
private Dictionary<string, string> CreateSearchDic(string MethodName, QueryTerm queryTerm) { Dictionary<string, string> cacheDic = new Dictionary<string, string>(); cacheDic.Add(CacheService.ServiceName, "ListController"); cacheDic.Add(CacheService.ServiceMethod, MethodName); cacheDic.Add("Province", queryTerm.Province.ToString()); cacheDic.Add("City", queryTerm.City.ToString()); cacheDic.Add("MediaCode", queryTerm.MediaCode.ToString()); cacheDic.Add("FormatCode", queryTerm.FormatCode.ToString()); cacheDic.Add("OwnerCode", queryTerm.OwnerCode.ToString()); cacheDic.Add("PeriodCode", queryTerm.PeriodCode.ToString()); cacheDic.Add("AuthStatus", queryTerm.AuthStatus.ToString()); cacheDic.Add("DeadLine", queryTerm.DeadLine.ToString()); cacheDic.Add("Order", queryTerm.Order.ToString()); cacheDic.Add("Descending", queryTerm.Descending.ToString()); cacheDic.Add("Price", queryTerm.Price.ToString()); cacheDic.Add("Page", queryTerm.Page.ToString()); return cacheDic; }
private bool canReadCache(QueryTerm queryTerm) { var dq = queryTerm.Dq; if (string.IsNullOrWhiteSpace(dq) && string.IsNullOrWhiteSpace(queryTerm.Query)) { return true; } else { if (!string.IsNullOrWhiteSpace(dq) && string.IsNullOrWhiteSpace(queryTerm.Query)) { try { var dqtime = DateTime.Now; bool success = DateTime.TryParse(dq, out dqtime); if (!success) { return false; } if (dqtime.ToString("yyyyMMdd").Equals(DateTime.Now.ToString("yyyyMMdd"))) { return false; } } catch (Exception ex) { return false; } return true; } return true; } }
private QuerySort GetSort(QueryTerm queryTerm) { QuerySort result = new QuerySort(); if (queryTerm.Order == 0) { result.SortDefault = true; } else if (queryTerm.Order == (int)SortProperty.Price) { if (queryTerm.Descending == (int)SortDirection.Descending) { result.SortPriceDesc = true; } else { result.SortPriceAsc = true; } } return result; }