Пример #1
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="barPosts">待更新的回帖集合</param>
        public void UpdateBarPost(IEnumerable <BarPost> barPosts)
        {
            IEnumerable <Document> docs       = BarIndexDocument.Convert(barPosts);
            IEnumerable <string>   barPostIds = barPosts.Select(n => n.ThreadId.ToString());

            searchEngine.Update(docs, barPostIds, BarIndexDocument.PostId);
        }
Пример #2
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="barPost">待更新的回帖</param>
        public void UpdateBarPost(BarPost barPost)
        {
            Document doc = BarIndexDocument.Convert(barPost);

            searchEngine.Update(doc, barPost.PostId.ToString(), BarIndexDocument.PostId);
        }
Пример #3
0
        /// <summary>
        /// 更新索引
        /// </summary>
        /// <param name="barThread">待更新的发帖</param>
        public void UpdateBarThread(BarThread barThread)
        {
            Document doc = BarIndexDocument.Convert(barThread);

            searchEngine.Update(doc, barThread.ThreadId.ToString(), BarIndexDocument.ThreadId);
        }
Пример #4
0
        /// <summary>
        /// 添加索引
        /// </summary>
        /// <param name="barPosts">待添加的回帖</param>
        public void InsertBarPost(IEnumerable <BarPost> barPosts)
        {
            IEnumerable <Document> docs = BarIndexDocument.Convert(barPosts);

            searchEngine.Insert(docs);
        }
Пример #5
0
        /// <summary>
        /// 添加索引
        /// </summary>
        /// <param name="barThreads">待添加的发帖</param>
        public void InsertBarThread(IEnumerable <BarThread> barThreads)
        {
            IEnumerable <Document> docs = BarIndexDocument.Convert(barThreads);

            searchEngine.Insert(docs);
        }
Пример #6
0
        /// <summary>
        /// 重建索引
        /// </summary>
        public void RebuildIndex()
        {
            bool hasData = false;

            //pageSize参数决定了每次批量取多少条数据进行索引。要注意的是,如果是分布式搜索,客户端会将这部分数据通过WCF传递给服务器端,而WCF默认的最大传输数据量是65535B,pageSize较大时这个设置显然是不够用的,WCF会报400错误;系统现在将最大传输量放宽了,但仍要注意一次不要传输过多,如遇异常,可适当调小pageSize的值
            int            pageSizeBarThread     = 100;
            int            pageIndexBarThread    = 1;
            long           totalRecordsBarThread = 0;
            bool           isBeginningBarThread  = true;
            bool           isEnddingBarThread    = false;
            BarThreadQuery barThreadQuery        = new BarThreadQuery();

            do
            {
                //分页获取帖子列表
                PagingDataSet <BarThread> barThreads = barThreadService.Gets(null, barThreadQuery, pageSizeBarThread, pageIndexBarThread);
                totalRecordsBarThread = barThreads.TotalRecords;
                if (totalRecordsBarThread > 0)
                {
                    hasData = true;
                }
                isEnddingBarThread = (pageSizeBarThread * pageIndexBarThread < totalRecordsBarThread) ? false : true;

                //重建索引
                List <BarThread> barThreadList = barThreads.ToList <BarThread>();

                IEnumerable <Document> docs = BarIndexDocument.Convert(barThreadList);

                searchEngine.RebuildIndex(docs, isBeginningBarThread, false);

                isBeginningBarThread = false;
                pageIndexBarThread++;
            }while (!isEnddingBarThread);

            int          pageSizeBarPost     = 100;
            int          pageIndexBarPost    = 1;
            long         totalRecordsBarPost = 0;
            bool         isEnddingBarPost    = false;
            BarPostQuery barPostQuery        = new BarPostQuery();

            do
            {
                //分页获取帖子列表
                PagingDataSet <BarPost> barPosts = barPostService.Gets(null, barPostQuery, pageSizeBarPost, pageIndexBarPost);
                totalRecordsBarPost = barPosts.TotalRecords;
                if (totalRecordsBarPost > 0)
                {
                    hasData = true;
                }
                isEnddingBarPost = (pageSizeBarPost * pageIndexBarPost < totalRecordsBarPost) ? false : true;

                //重建索引
                List <BarPost> barPostList = barPosts.ToList <BarPost>();

                IEnumerable <Document> docs = BarIndexDocument.Convert(barPostList);

                searchEngine.RebuildIndex(docs, false, false);

                pageIndexBarPost++;
            }while (!isEnddingBarPost);

            if (hasData)
            {
                searchEngine.RebuildIndex(null, false, true);
            }
        }