The following example assigns a smart search index to a site.
privatebool AddSearchIndexToSite() {
// Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
if (index != null) { int indexId = index.IndexID; int siteId = CMSContext.CurrentSiteID; // Save the binding SearchIndexSiteInfoProvider.AddSearchIndexToSite(indexId, siteId); returntrue; } returnfalse; }
The following example removes a search index from a site.
privatebool RemoveSearchIndexFromSite() {
// Get the search index SearchIndexInfo removeIndex = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
if (removeIndex != null) { int siteId = CMSContext.CurrentSiteID;
// Get the binding SearchIndexSiteInfo indexSite = SearchIndexSiteInfoProvider.GetSearchIndexSiteInfo(removeIndex.IndexID, siteId);
// Delete the binding SearchIndexSiteInfoProvider.DeleteSearchIndexSiteInfo(indexSite); returntrue; } returnfalse; }