Пример #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="microblogs">待更新的微博集合</param>
        public void Update(IEnumerable <MicroblogEntity> microblogs)
        {
            IEnumerable <Document> docs         = MicroblogIndexDocument.Convert(microblogs);
            List <string>          microblogIds = new List <string>();

            foreach (MicroblogEntity microblog in microblogs)
            {
                microblogIds.Add(microblog.MicroblogId.ToString());
            }
            searchEngine.Update(docs, microblogIds, MicroblogIndexDocument.MicroblogId);
        }
Пример #3
0
        /// <summary>
        /// 添加索引
        /// </summary>
        /// <param name="microblogs">待添加的微博</param>
        public void Insert(IEnumerable <MicroblogEntity> microblogs)
        {
            List <Document> docs = new List <Document>();

            foreach (var microblog in microblogs)
            {
                Document doc = MicroblogIndexDocument.Convert(microblog);
                if (doc != null)
                {
                    docs.Add(doc);
                }
            }
            searchEngine.Insert(docs);
        }
Пример #4
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="microblog">待更新的微博</param>
        public void Update(MicroblogEntity microblog)
        {
            Document doc = MicroblogIndexDocument.Convert(microblog);

            searchEngine.Update(doc, microblog.MicroblogId.ToString(), MicroblogIndexDocument.MicroblogId);
        }