/// <summary> /// 获取Post预览图 /// </summary> /// <param name="customSQL">自定义SQL</param> /// <param name="inputTags">未经处理的标签</param> /// <param name="ratingArray">分级</param> /// <param name="preferArray">偏好</param> /// <param name="column">按此列排序</param> /// <param name="orderMode">排序模式</param> /// <param name="siteArray">图站</param> /// <returns></returns> public static List <PostPreviewInfo> GetPostPreviewInfo(string customSQL, string inputTags, Rating[] ratingArray, Prefer[] preferArray, PostOrderBy column, OrderMode orderMode, Site[] siteArray) { //多线程查询结果集 List <PostPreviewInfo> result = new List <PostPreviewInfo>(); //将参数打包 Dictionary <string, object>[] paramDicArray = new Dictionary <string, object> [siteArray.Length]; //根据查询图站数量创建线程 Task <List <PostPreviewInfo> >[] tasks = new Task <List <PostPreviewInfo> > [siteArray.Length]; for (int x = 0; x < siteArray.Length; x++) { paramDicArray[x] = new Dictionary <string, object>(); paramDicArray[x].Add("customSQL", customSQL); paramDicArray[x].Add("inputTags", inputTags); paramDicArray[x].Add("ratingArray", ratingArray); paramDicArray[x].Add("column", column); paramDicArray[x].Add("site", siteArray[x]); tasks[x] = new Task <List <PostPreviewInfo> >(p => { Dictionary <string, object> pDic = (Dictionary <string, object>)p; return(GetOneSitePostPreview((string)pDic["customSQL"], (string)pDic["inputTags"], (Site)pDic["site"], (PostOrderBy)pDic["column"], (Rating[])pDic["ratingArray"])); }, paramDicArray[x]); } //开启多线程查询 foreach (var t in tasks) { t.Start(); } Task.WaitAll(tasks); //合并多线程结果集 foreach (var t in tasks) { result.AddRange(t.Result); } IEnumerable <PostPreviewInfo> temp = result; //偏好 List <PostPreviewInfo> preferList = Preference.GetPostPrefer(preferArray); if (preferList == null) { temp = result; } else { //差集 if (preferArray.Contains(Prefer.Normal)) { temp = result.Except(preferList); } //交集 else { temp = result.Intersect(preferList); } } //去除重复 if (siteArray.Length > 1) { //分数相加 if (column == PostOrderBy.score) { temp = temp.GroupBy(a => a.file_md5).Select(b => new PostPreviewInfo() { file_md5 = b.First().file_md5, order_column = b.Sum(c => Convert.ToInt32(c.order_column)) }); } //发布日期选最早 else if (column == PostOrderBy.submitted_on) { temp = temp.GroupBy(a => a.file_md5).Select(b => b.Min()); } else { temp = temp.GroupBy(a => a.file_md5).Select(b => b.First()); } } //排序 if (orderMode == OrderMode.ASC) { temp = temp.OrderBy(c => c.order_column); } else { temp = temp.OrderByDescending(c => c.order_column); } return(temp.ToList()); }
/// <summary> /// 获取Pool预览图 /// </summary> /// <param name="inputName">用户输入的名称</param> /// <param name="ratingArray">分级</param> /// <param name="preferArray">偏好</param> /// <param name="column">按此列排序</param> /// <param name="orderMode">排序模式</param> /// <param name="siteArray">图站</param> /// <returns></returns> public static List <PoolPreviewInfo> GetPoolPreview(string inputName, Rating[] ratingArray, Prefer[] preferArray, PoolOrderBy column, OrderMode orderMode, Site[] siteArray) { //多线程查询结果集 List <PoolPreviewInfo> result = new List <PoolPreviewInfo>(); //将参数打包 Dictionary <string, object>[] paramDicArray = new Dictionary <string, object> [siteArray.Length]; //根据查询图站数量创建线程 Task <List <PoolPreviewInfo> >[] tasks = new Task <List <PoolPreviewInfo> > [siteArray.Length]; for (int x = 0; x < siteArray.Length; x++) { paramDicArray[x] = new Dictionary <string, object>(); paramDicArray[x].Add("inputName", inputName); paramDicArray[x].Add("ratingArray", ratingArray); paramDicArray[x].Add("column", column); paramDicArray[x].Add("site", siteArray[x]); tasks[x] = new Task <List <PoolPreviewInfo> >(p => { Dictionary <string, object> pDic = (Dictionary <string, object>)p; return(GetOneSitePoolPreview((string)pDic["inputName"], (Site)pDic["site"], (PoolOrderBy)pDic["column"], (Rating[])pDic["ratingArray"])); }, paramDicArray[x]); } //开启多线程查询 foreach (var t in tasks) { t.Start(); } Task.WaitAll(tasks); //合并多线程结果集 foreach (var t in tasks) { result.AddRange(t.Result); } IEnumerable <PoolPreviewInfo> temp; //偏好 List <PoolPreviewInfo> preferList = Preference.GetPoolPrefer(preferArray); if (preferList == null || preferList.Count == 0) { temp = result; } else { //差集 if (preferArray.Contains(Prefer.Normal)) { temp = result.Except(preferList); } //交集 else { temp = result.Intersect(preferList); } } //排序 if (orderMode == OrderMode.ASC) { temp = temp.OrderBy(c => c.order_column); } else { temp = temp.OrderByDescending(c => c.order_column); } return(temp.ToList()); }