Hello Peter,
You can execute the same code, which is executed when you rebuild smart search index manually in
Site Manager -> Administration -> Smart search -> edit -> General tab -> Rebuild link button. This code can be found in
<project folder>\CMSModules\SmartSearch\Controls\UI\SearchIndex_General.ascx.cs.
At first, you need to create SmartSearchInfo object:
protected SearchIndexInfo sii = null; //(around line 26)
And assign proper index to it:
// Get search index info //(around line 65)
sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID);
{
// see code inside
}
If you know ID of selected index, you can use it directly.
Then you can rebuild index using this code:
if (sii != null)
{
SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName);
}
lblInfo.Text = ResHelper.GetString("srch.index.rebuildstarted");
lblInfo.Visible = true;
// Reload info panel
System.Threading.Thread.Sleep(100);
ReloadInfoPanel();
}
Please take an inspiration from file above for more details.
Best regards,
Martin Danko