/// <summary> /// 批量更新索引 /// </summary> /// <param name="photos">Photo集合</param> public void Update(IEnumerable <Photo> photos) { IEnumerable <Document> docs = PhotoIndexDocument.Convert(photos); IEnumerable <string> photoIds = photos.Select(n => n.PhotoId.ToString()); searchEngine.Update(docs, photoIds, PhotoIndexDocument.PhotoId); }
/// <summary> /// 重建索引 /// </summary> public void RebuildIndex() { int pageSize = 1000; int pageIndex = 1; long totalRecords = 0; bool isBeginning = true; bool isEndding = false; do { PagingDataSet <Photo> photos = photoService.GetPhotosForAdmin(null, null, null, null, null, null, pageSize, pageIndex); totalRecords = photos.TotalRecords; isEndding = (pageSize * pageIndex < totalRecords) ? false : true; List <Photo> photoList = photos.ToList <Photo>(); IEnumerable <Document> docs = PhotoIndexDocument.Convert(photoList); searchEngine.RebuildIndex(docs, isBeginning, isEndding); isBeginning = false; pageIndex++; } while (!isEndding); }
/// <summary> /// 更新索引 /// </summary> /// <param name="photo">要更新的Photo</param> public void Update(Photo photo) { Document doc = PhotoIndexDocument.Convert(photo); searchEngine.Update(doc, photo.PhotoId.ToString(), PhotoIndexDocument.PhotoId); }
/// <summary> /// 批量添加索引 /// </summary> /// <param name="photos">Photo集合</param> public void Insert(IEnumerable <Photo> photos) { IEnumerable <Document> docs = PhotoIndexDocument.Convert(photos); searchEngine.Insert(docs); }