/// <summary> /// 更新索引 /// </summary> /// <param name="blogThreads">待更新的日志集合</param> public void Update(IEnumerable <BlogThread> blogThreads) { IEnumerable <Document> docs = BlogIndexDocument.Convert(blogThreads); IEnumerable <string> blogThreadIds = blogThreads.Select(n => n.ThreadId.ToString()); searchEngine.Update(docs, blogThreadIds, BlogIndexDocument.ThreadId); }
/// <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; do { //分页获取帖子列表 PagingDataSet <BlogThread> blogThreads = blogThreadService.GetsForAdmin(null, null, null, null, null, null, pageSize, pageIndex); totalRecords = blogThreads.TotalRecords; isEndding = (pageSize * pageIndex < totalRecords) ? false : true; //重建索引 List <BlogThread> blogThreadList = blogThreads.ToList <BlogThread>(); IEnumerable <Document> docs = BlogIndexDocument.Convert(blogThreadList); searchEngine.RebuildIndex(docs, isBeginning, isEndding); isBeginning = false; pageIndex++; }while (!isEndding); }
/// <summary> /// 更新索引 /// </summary> /// <param name="blogThread">待更新的日志</param> public void Update(BlogThread blogThread) { Document doc = BlogIndexDocument.Convert(blogThread); searchEngine.Update(doc, blogThread.ThreadId.ToString(), BlogIndexDocument.ThreadId); }
/// <summary> /// 添加索引 /// </summary> /// <param name="blogThreads">待添加的日志</param> public void Insert(IEnumerable <BlogThread> blogThreads) { IEnumerable <Document> docs = BlogIndexDocument.Convert(blogThreads); searchEngine.Insert(docs); }