Kentico CMS 6.0 Developer's Guide

Managing search index sites

Managing search index sites

Previous topic Next topic Mail us feedback on this topic!  

Managing search index sites

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example assigns a smart search index to a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}

 

The following example removes a search index from a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}