Esempio n. 1
0
        /// <summary>
        /// 重建索引
        /// </summary>
        public void RebuildIndex()
        {
            //pageSize参数决定了每次批量取多少条数据进行索引。要注意的是,如果是分布式搜索,客户端会将这部分数据通过WCF传递给服务器端,而WCF默认的最大传输数据量是65535B,pageSize较大时这个设置显然是不够用的,WCF会报400错误;系统现在将最大传输量放宽了,但仍要注意一次不要传输过多,如遇异常,可适当调小pageSize的值
            int       pageSize     = 1000;
            int       pageIndex    = 1;
            long      totalRecords = 0;
            bool      isBeginning  = true;
            bool      isEndding    = false;
            UserQuery query        = new UserQuery();

            long     followedUserId = 0;
            Document doc            = null;

            do
            {
                //分页获取粉丝列表
                PagingDataSet <User> users = userService.GetUsers(query, pageSize, pageIndex);

                totalRecords = users.TotalRecords;
                IEnumerable <long> followerUserIds = users.Select(n => n.UserId);

                isEndding = (pageSize * pageIndex < totalRecords) ? false : true;

                //根据粉丝列表批量查询关注用户列表
                IEnumerable <FollowEntity> followedUsers = followService.GetFollowedUsers(followerUserIds);

                //循环关注用户列表(已按照UserId排序),对每个UserId建立索引
                List <Document> docs = new List <Document>();
                foreach (FollowEntity followedUser in followedUsers)
                {
                    //判断当前记录的被关注用户的ID是否与上一条的被关注用户的ID相同。
                    //如果相同,说明属于同一个用户的关注对象
                    if (followedUser.UserId == followedUserId)
                    {
                        doc.Add(new Field(FollowedUserIds, followedUser.FollowedUserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    }
                    else
                    {
                        //fixed by jiangshl

                        //对于下一个用户,需要重新构建Document对象
                        doc = new Document();
                        doc.Add(new Field(UserId, followedUser.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                        doc.Add(new Field(FollowedUserIds, followedUser.FollowedUserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                        docs.Add(doc);

                        followedUserId = followedUser.UserId;
                    }
                }

                searchEngine.RebuildIndex(docs, isBeginning, isEndding);

                isBeginning = false;
                pageIndex++;
            }while (!isEndding);
        }
Esempio n. 2
0
        public ActionResult ManageBars(ManageBarEditModel model, int pageIndex = 1)
        {
            pageResourceManager.InsertTitlePart("帖吧管理");

            //long userId = Request.QueryString.Gets<long>(model.UserId, new List<long>()).FirstOrDefault();

            BarSectionQuery query  = model.GetQuery();
            long            userId = Request.QueryString.Gets <long>("UserId", new List <long>()).FirstOrDefault();

            if (userId > 0)
            {
                query.UserId = userId;
            }
            ViewData["UserId"] = query.UserId;

            PagingDataSet <BarSection> sections = barSectionService.Gets(TenantTypeIds.Instance().Bar(), query, model.PageSize ?? 20, pageIndex);

            //为提升性能,批量获取吧主用户
            userService.GetFullUsers(sections.Select(n => n.UserId));
            ViewData["BarSections"] = sections;
            //foreach (var item in sections)
            //{
            //


            //    ViewData["BarSections-Category-" + item.SectionId] = categoryService.GetOwnerCategories(item.SectionId, TenantTypeIds.Instance().BarSection());
            //}



            PagingDataSet <Category> categories = categoryService.GetCategories(PubliclyAuditStatus.Success, TenantTypeIds.Instance().BarSection(), null, 1);



            ViewData["CategoryId"] = new SelectList(categories, "CategoryId", "CategoryName", model.CategoryId);


            //Dictionary<bool, string> enabledValues = new Dictionary<bool, string> { { true, "是" }, { false, "否" } };
            //ViewData["Enabled"] = new SelectList(enabledValues.Select(n => new { text = n.Value, value = n.Key.ToString().ToLower() }), "value", "text", model.Enabled);



            List <SelectListItem> enabledSelectLists = new List <SelectListItem> {
                new SelectListItem {
                    Text = "是", Value = true.ToString()
                },
                new SelectListItem {
                    Text = "否", Value = false.ToString()
                }
            };

            ViewData["Enabled"] = new SelectList(enabledSelectLists, "Value", "Text", model.Enabled);
            return(View(model));
        }
Esempio n. 3
0
        /// <summary>
        /// 微博图片模式数据页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="tenantTypeId"></param>
        /// <param name="mediaType"></param>
        /// <param name="isOriginal"></param>
        /// <param name="sortBy"></param>
        /// <returns></returns>
        public ActionResult _Waterfall(int pageIndex = 1, string tenantTypeId = "", MediaType?mediaType = null, bool?isOriginal = null, SortBy_Microblog sortBy = SortBy_Microblog.DateCreated)
        {
            //获取微博分页数据
            PagingDataSet <MicroblogEntity> MicroblogEntities = microblogService.GetPagings(pageIndex, tenantTypeId: TenantTypeIds.Instance().User(), mediaType: mediaType, sortBy: sortBy);

            //获取微博图片
            AttachmentService <Attachment> attachementService = new AttachmentService <Attachment>(TenantTypeIds.Instance().Microblog());

            foreach (var MicroblogEntity in MicroblogEntities.Where(n => n.HasPhoto))
            {
                IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(MicroblogEntity.MicroblogId);

                if (attachments != null && attachments.Count <Attachment>() > 0)
                {
                    MicroblogEntity.ImageWidth = attachments.First().Width;
                    MicroblogEntity.ImageUrl   = SiteUrls.Instance().ImageUrl(attachments.First(), TenantTypeIds.Instance().Microblog(), ImageSizeTypeKeys.Instance().Big());
                }
            }

            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                //设置当前登录用户对当前页用户的关注情况
                Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();
                foreach (var user in MicroblogEntities.Select(m => m.User))
                {
                    if (user == null)
                    {
                        continue;
                    }

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

            return(View(MicroblogEntities.AsEnumerable <MicroblogEntity>()));
        }
Esempio n. 4
0
        /// <summary>
        /// 排行榜
        /// </summary>
        //[DonutOutputCache(CacheProfile = "Frequently")]
        public ActionResult Ranking(SortBy_User?sortBy = SortBy_User.PreWeekHitTimes, int pageIndex = 1)
        {
            PagingDataSet <User> users = userService.GetPagingUsers(sortBy, pageIndex, 20);
            IUser CurrentUser          = UserContext.CurrentUser;

            ViewData["sortBy"] = sortBy;

            //查询用户标签
            IEnumerable <long>                itemInTagIds   = tagService.GetItemInTagIdsByItemIds(users.Select(n => n.UserId));
            IEnumerable <ItemInTag>           itemInTags     = tagService.GetItemInTags(itemInTagIds);
            Dictionary <long, List <string> > userTagNameDic = new Dictionary <long, List <string> >();

            foreach (ItemInTag itemInTag in itemInTags)
            {
                if (userTagNameDic.ContainsKey(itemInTag.ItemId))
                {
                    List <string> tagNames = userTagNameDic[itemInTag.ItemId];
                    tagNames.Add(itemInTag.TagName);
                }
                else
                {
                    List <string> tagNames = new List <string>();
                    tagNames.Add(itemInTag.TagName);
                    userTagNameDic.Add(itemInTag.ItemId, tagNames);
                }
            }
            ViewData["userTagNameDic"] = userTagNameDic;

            pageResourceManager.InsertTitlePart("用户排行");

            return(View(users));
        }
Esempio n. 5
0
        /// <summary>
        /// 排行榜
        /// </summary>
        /// <returns></returns>
        public ActionResult Ranking(SortBy_User?sortBy = null, int pageIndex = 1)
        {
            if (sortBy == null)
            {
                sortBy = SortBy_User.HitTimes;
            }
            PagingDataSet <User> users = userService.GetPagingUsers(sortBy, pageIndex, 20);
            IUser CurrentUser          = UserContext.CurrentUser;

            if (CurrentUser != null)
            {
                //设置当前登录用户对当前页用户的关注情况
                Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();
                foreach (var user in users)
                {
                    //如果当前登录用户关注了该用户
                    if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                    {
                        isCurrentUserFollowDic[user.UserId] = true;
                    }
                    else
                    {
                        isCurrentUserFollowDic[user.UserId] = false;
                    }
                }
                ViewData["sortBy"] = sortBy;
                ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            }

            //查询用户标签
            IEnumerable <long>                itemInTagIds   = tagService.GetItemInTagIdsByItemIds(users.Select(n => n.UserId));
            IEnumerable <ItemInTag>           itemInTags     = tagService.GetItemInTags(itemInTagIds);
            Dictionary <long, List <string> > userTagNameDic = new Dictionary <long, List <string> >();

            foreach (ItemInTag itemInTag in itemInTags)
            {
                if (userTagNameDic.ContainsKey(itemInTag.ItemId))
                {
                    List <string> tagNames = userTagNameDic[itemInTag.ItemId];
                    tagNames.Add(itemInTag.TagName);
                }
                else
                {
                    List <string> tagNames = new List <string>();
                    tagNames.Add(itemInTag.TagName);
                    userTagNameDic.Add(itemInTag.ItemId, tagNames);
                }
            }
            ViewData["userTagNameDic"] = userTagNameDic;

            pageResourceManager.InsertTitlePart("用户排行");

            return(View(users));
        }