Ejemplo n.º 1
0
        /// <summary>
        /// 任务执行的内容
        /// </summary>
        /// <param name="taskDetail">任务配置状态信息</param>
        public void Execute(TaskDetail taskDetail)
        {
            if (searcher == null)
            {
                //检查是否分布式运行环境
                bool distributedDeploy = Utility.IsDistributedDeploy();

                if (distributedDeploy)
                {
                    searcher = new FollowUserSearcher(SearchEngineService.GetSearchEngine("~/App_Data/IndexFiles/FollowUser"));
                }
                else
                {
                    searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
                }
            }

            //根据上次执行时间从数据库取关注实体列表
            DateTime lastStart = new DateTime(1900, 1, 1);
            if (taskDetail != null && taskDetail.LastStart.HasValue)
            {
                lastStart = taskDetail.LastStart.Value;
            }

            IEnumerable<long> userIds = followService.GetRecentFollowerUserIds(lastStart);

            searcher.Update(userIds);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 可能感兴趣的人-有共同关注的人
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <returns></returns>
        public ActionResult _InterestedWithFollows(int pageIndex = 1)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            Dictionary <long, IEnumerable <long> > followedUserIdDic = null;
            Dictionary <long, User> followedUserDic = null;

            FollowUserSearcher   searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
            PagingDataSet <User> users    = searcher.SearchInterestedWithFollows(CurrentUser.UserId, pageIndex, pageSize, out followedUserIdDic, out followedUserDic);

            ViewData["followedUserIdDic"] = followedUserIdDic;
            ViewData["followedUserDic"]   = followedUserDic;

            return(View(users));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 可能感兴趣的人-有共同关注的人
        /// </summary>
        /// <param name="pageIndex">分页页码</param>
        /// <returns></returns>
        public ActionResult _InterestedWithFollows(int pageIndex = 1)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            Dictionary <long, IEnumerable <long> > followedUserIdDic = null;
            Dictionary <long, User> followedUserDic = null;

            FollowUserSearcher   searcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
            PagingDataSet <User> users    = searcher.SearchInterestedWithFollows(CurrentUser.UserId, pageIndex, pageSize, out followedUserIdDic, out followedUserDic);


            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (var user in users)
            {
                //如果当前登录用户关注了该用户
                if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                {
                    isCurrentUserFollowDic.Add(user.UserId, true);
                }
                else
                {
                    isCurrentUserFollowDic.Add(user.UserId, false);
                }
            }
            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            ViewData["followedUserIdDic"]      = followedUserIdDic;
            ViewData["followedUserDic"]        = followedUserDic;

            return(View(users));
        }
Ejemplo n.º 4
0
        public ActionResult _InterestedWithAll(int pageSize = 6, int pageIndex = 1, string view = null)
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(null);
            }

            //查询同一公司的(优先级最高)
            Dictionary <long, IEnumerable <string> > companyNameDic = null;
            UserSearcher         userSearcher      = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE);
            PagingDataSet <User> usersWithCompanys = userSearcher.SearchInterestedWithCompanys(CurrentUser.UserId, 1, 30, out companyNameDic);

            //存储感兴趣的人
            List <User> userList = usersWithCompanys.ToList();
            //存储感兴趣的类型
            Dictionary <long, string> interestedDic = usersWithCompanys.ToDictionary(key => key.UserId, value => "WithCompanys");

            //查询有共同关注用户的(优先级第二)
            Dictionary <long, IEnumerable <long> > followedUserIdDic = null;
            Dictionary <long, User> followedUserDic    = null;
            FollowUserSearcher      followUserSearcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE);
            PagingDataSet <User>    usersWithFollows   = followUserSearcher.SearchInterestedWithFollows(CurrentUser.UserId, 1, 30, out followedUserIdDic, out followedUserDic);

            foreach (User user in usersWithFollows)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithFollows");
                }
            }

            //查询同一个学校的(优先级第三)
            Dictionary <long, IEnumerable <string> > schoolNameDic = null;
            PagingDataSet <User> usersWithSchools = userSearcher.SearchInterestedWithSchools(CurrentUser.UserId, 1, 30, out schoolNameDic);

            foreach (User user in usersWithSchools)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithSchools");
                }
            }

            //查询相同标签的(优先级最低)
            Dictionary <long, IEnumerable <string> > tagNameDic = null;
            PagingDataSet <User> usersWithTags = userSearcher.SearchInterestedWithTags(CurrentUser.UserId, 1, 30, out tagNameDic);

            foreach (User user in usersWithTags)
            {
                if (!interestedDic.ContainsKey(user.UserId))
                {
                    userList.Add(user);
                    interestedDic.Add(user.UserId, "WithTags");
                }
            }


            ViewData["followedUserIdDic"] = followedUserIdDic;
            ViewData["followedUserDic"]   = followedUserDic;
            ViewData["companyNameDic"]    = companyNameDic;
            ViewData["schoolNameDic"]     = schoolNameDic;
            ViewData["tagNameDic"]        = tagNameDic;
            ViewData["interestedDic"]     = interestedDic;

            //不指定View,则返回固定的页面,随机显示
            if (string.IsNullOrEmpty(view))
            {
                //随机从用户列表中取pageSize对应的对象组装成新的集合
                List <User> randomUserList = null;
                if (userList.Count <= pageSize)
                {
                    randomUserList = userList;
                }
                else
                {
                    Dictionary <int, User> randomUserDic = new Dictionary <int, User>();
                    Random random = new Random();

                    while (randomUserDic.Count < pageSize)
                    {
                        int index = random.Next(0, userList.Count);
                        if (!randomUserDic.ContainsKey(index))
                        {
                            User user = userList[index];
                            randomUserDic.Add(index, user);
                        }
                    }

                    randomUserList = randomUserDic.OrderBy(n => n.Key).Select(n => n.Value).ToList();
                }

                return(View(randomUserList));
            }
            //指定view,分页显示
            else
            {
                ViewData["pageCount"] = userList.Count / pageSize + 1;
                return(View(view, userList.Skip(pageSize * (pageIndex - 1)).Take(pageSize)));
            }
        }