/// <summary> /// Bulks the index documents. /// </summary> public void BulkIndexDocuments() { List <IndexModelBase> indexableItems = new List <IndexModelBase>(); RockContext rockContext = new RockContext(); // return people var groups = new GroupService(rockContext).Queryable().AsNoTracking() .Where(g => g.IsActive == true && g.GroupType.IsIndexEnabled == true); int recordCounter = 0; foreach (var group in groups) { var indexableGroup = GroupIndex.LoadByModel(group); indexableItems.Add(indexableGroup); recordCounter++; if (recordCounter > 100) { IndexContainer.IndexDocuments(indexableItems); indexableItems = new List <IndexModelBase>(); recordCounter = 0; } } IndexContainer.IndexDocuments(indexableItems); }
/// <summary> /// Indexes the document. /// </summary> /// <param name="id"></param> public void IndexDocument(int id) { var groupEntity = new GroupService(new RockContext()).Get(id); // check that this group type is set to be indexed. if (groupEntity.GroupType.IsIndexEnabled && groupEntity.IsActive) { var indexItem = GroupIndex.LoadByModel(groupEntity); IndexContainer.IndexDocument(indexItem); } }
/// <summary> /// Deletes the indexed documents by group type. /// </summary> /// <param name="groupTypeId">The group type identifier.</param> public void DeleteIndexedDocumentsByGroupType(int groupTypeId) { var groups = new GroupService(new RockContext()).Queryable() .Where(i => i.GroupTypeId == groupTypeId); foreach (var group in groups) { var indexableGroup = GroupIndex.LoadByModel(group); IndexContainer.DeleteDocument <GroupIndex>(indexableGroup); } }
/// <summary> /// Bulks the index documents by content channel. /// </summary> /// <param name="groupTypeId">The content channel identifier.</param> public void BulkIndexDocumentsByGroupType(int groupTypeId) { List <GroupIndex> indexableGroups = new List <GroupIndex>(); // return all approved content channel items that are in content channels that should be indexed RockContext rockContext = new RockContext(); var groups = new GroupService(rockContext).Queryable() .Where(g => g.GroupTypeId == groupTypeId && g.IsActive); foreach (var group in groups) { var indexableChannelItem = GroupIndex.LoadByModel(group); indexableGroups.Add(indexableChannelItem); } IndexContainer.IndexDocuments(indexableGroups); }