示例#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;
            MicroblogQuery query        = new MicroblogQuery();

            do
            {
                //分页获取微博列表
                PagingDataSet <MicroblogEntity> microblogs = microBlogService.GetMicroblogs(query, pageSize, pageIndex);
                totalRecords = microblogs.TotalRecords;

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

                //重建索引
                List <MicroblogEntity> microblogsList = microblogs.ToList <MicroblogEntity>();

                IEnumerable <Document> docs = MicroblogIndexDocument.Convert(microblogsList);

                searchEngine.RebuildIndex(docs, isBeginning, isEndding);

                isBeginning = false;
                pageIndex++;
            }while (!isEndding);
        }
示例#2
0
        /// <summary>
        /// 管理员后台获取列表方法
        /// </summary>
        /// <param name="query">查询条件</param>
        ///<param name="pageSize">每页显示内容数</param>
        ///<param name="pageIndex">页码</param>
        /// <returns></returns>
        public PagingDataSet <MicroblogEntity> GetMicroblogs(MicroblogQuery query, int pageSize, int pageIndex)
        {
            Sql sql = Sql.Builder;

            //reply:已修改
            sql.Select("*")
            .From("spb_Microblogs");
            BuildSqlWhere_MicroblogQuery(query, ref sql);
            return(GetPagingEntities(pageSize, pageIndex, sql));
        }
        public ActionResult ManageMicroblogs(int pageIndex = 1, string userId = null, string keyword = null, MediaType?mediaType = null, AuditStatus?auditStatus = null, DateTime?startdate = null, DateTime?enddate = null, int pageSize = 20, string tenantTypeId = null, long?ownerId = null)
        {
            pageResourceManager.InsertTitlePart("微博管理");

            #region 组装搜索条件
            MicroblogQuery query = new MicroblogQuery();

            long?id = null;
            if (!string.IsNullOrEmpty(userId))
            {
                userId = userId.TrimStart(',').TrimEnd(',');
                if (!string.IsNullOrEmpty(userId))
                {
                    id = long.Parse(userId);
                }
            }
            query.OwnerId      = ownerId;
            query.Keyword      = keyword;
            query.UserId       = id;
            query.MediaType    = mediaType;
            query.AuditStatus  = auditStatus;
            query.TenantTypeId = tenantTypeId;
            if (startdate != DateTime.MinValue)
            {
                query.StartDate = startdate;
            }

            if (enddate != DateTime.MinValue && enddate.HasValue)
            {
                query.EndDate = enddate.Value.AddDays(1);
            }

            #endregion

            ViewData["userId"] = id;
            PagingDataSet <MicroblogEntity> microblogs = microblogService.GetMicroblogs(query, pageSize, pageIndex);
            if (tenantTypeId == null)
            {
                tenantTypeId = TenantTypeIds.Instance().User();
            }
            ViewData["tenantTypeId"] = tenantTypeId;
            return(View(microblogs));
        }
示例#4
0
        /// <summary>
        /// 从MicroblogQuery构建PetaPoco.Sql的where条件
        /// </summary>
        /// <param name="query">MicroblogQuery查询条件</param>
        /// <param name="sql">PetaPoco.Sql对象</param>
        private void BuildSqlWhere_MicroblogQuery(MicroblogQuery query, ref PetaPoco.Sql sql)
        {
            if (sql == null)
            {
                sql = PetaPoco.Sql.Builder;
            }

            if (query.UserId.HasValue)
            {
                sql.Where("UserId = @0", query.UserId);
            }

            if (!string.IsNullOrEmpty(query.TenantTypeId))
            {
                sql.Where("TenantTypeId = @0", query.TenantTypeId);
            }

            if (query.OwnerId.HasValue)
            {
                sql.Where("OwnerId = @0", query.OwnerId);
            }

            if (query.isOriginal.HasValue && query.isOriginal.Value)
            {
                sql.Where("OriginalMicroblogId = 0");
            }
            else if (query.MediaType.HasValue)
            {
                switch (query.MediaType)
                {
                case MediaType.Image:
                    sql.Where("HasPhoto = 1");
                    break;

                case MediaType.Video:
                    sql.Where("HasVideo = 1");
                    break;

                case MediaType.Audio:
                    sql.Where("HasMusic = 1");
                    break;
                }
            }

            if (!string.IsNullOrEmpty(query.Keyword))
            {
                sql.Where("Body like @0", "%" + StringUtility.StripSQLInjection(query.Keyword) + "%");
            }

            if (query.StartDate.HasValue)
            {
                sql.Where("DateCreated >= @0", query.StartDate);
            }

            //reply:已修改
            if (query.EndDate.HasValue)
            {
                sql.Where("DateCreated < @0", query.EndDate.Value.AddDays(1));
            }

            if (query.AuditStatus.HasValue)
            {
                sql.Where("AuditStatus  = @0", (int)query.AuditStatus);
            }

            sql.OrderBy("MicroblogId desc");
        }
示例#5
0
 /// <summary>
 /// 管理员后台获取列表方法
 /// </summary>
 /// <param name="query">查询条件</param>
 ///<param name="pageSize">每页显示内容数</param>
 ///<param name="pageIndex">页码</param>
 /// <returns></returns>
 public PagingDataSet <MicroblogEntity> GetMicroblogs(MicroblogQuery query, int pageSize, int pageIndex)
 {
     return(microblogRepository.GetMicroblogs(query, pageSize, pageIndex));
 }