public void Add(IEnumerable<Post> posts) { var batch = new List<Document>(batchSize); foreach (var post in posts) { var doc = new Document(post.Id.ToString()); doc.AddTimestamp(post.CreationDate); doc.AddField("title", post.Title); doc.AddField("text", post.Body); var answerCount = post.AnswerCount ?? 0; doc.AddVariable(0, answerCount); AddRangeFacet(doc, "answers", answerCount, new[] { 10, 20, 30, 40, 50 }); var favoriteCount = post.FavoriteCount ?? 0; doc.AddVariable(1, favoriteCount); AddRangeFacet(doc, "favorites", favoriteCount, new[] { 10, 20, 30, 40, 50 }); var commentCount = post.CommentCount ?? 0; doc.AddVariable(2, commentCount); AddRangeFacet(doc, "comments", commentCount, new[] { 10, 20, 30, 40, 50 }); batch.Add(doc); if (batch.Count == batch.Capacity) { index.AddDocuments(batch); batch.Clear(); } } if (batch.Count > 0) index.AddDocuments(batch); }