public static ArticleIndex Create(DomainModel.Article model) { var article = new ArticleIndex { Id = model.ArticleID.ToString(), Lid = model.LID, Title = model.DisplayTitle, Summary = model.Abstract, Content = model.Body, MemberOnly = model.OnlyForMembers, Approved = model.Approved ? "1" : "0", Category = model.Category.DisplayTitle, SeriesTag = model.Series, CreatedBy = model.AddedBy, ReleasedOn = new DateTimeOffset(model.ReleaseDate) }; return(article); }
public async Task UploadIndex(IContentRepository repository, DateTime updateSince) { int total = repository.Articles.Where(x => x.UpdatedDate > updateSince).Count(); int next = 0; while (next < total) { var articles = repository.Articles.Where(x => x.UpdatedDate > updateSince).Include(x => x.Category).OrderBy(x => x.UpdatedDate).Skip(next).Take(UpdateBatchSize); IList <IndexAction <ArticleIndex> > actions = new List <IndexAction <ArticleIndex> >(); foreach (var article in articles) { actions.Add( new IndexAction <ArticleIndex>() { ActionType = IndexActionType.Upload, Document = ArticleIndex.Create(article) } ); } var result = await _indexClient.Documents.IndexAsync(new IndexBatch <ArticleIndex>(actions)); next += UpdateBatchSize; } }