The following sample code shows how you can modify the Display name of an existing search index:
[C#]
using CMS.SiteProvider;
...
// Get index object from database by index code name SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo("TestIndex");
// If index exists if (sii != null) { // Update some property sii.IndexDisplayName += " updated";
// Save to database SearchIndexInfoProvider.SetSearchIndexInfo(sii); } |
The following sample code shows how you can create a new search index, assign a site and culture to it and add it to the system:
[C#]
using System; using CMS.SiteProvider; using CMS.SettingsProvider; using CMS.CMSHelper;
...
// Create empty index object SearchIndexInfo sii = new SearchIndexInfo();
// Set properties sii.IndexIsCommunityGroup = false; sii.IndexName = "TestIndex"; sii.IndexDisplayName = "Test index"; sii.IndexType = PredefinedObjectType.DOCUMENT; sii.IndexAnalyzerType = AnalyzerTypeEnum.StandardAnalyzer; sii.StopWordsFile = ""; sii.CustomAnalyzerName = "";
// Create new index settings SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
// Set setting properties sisi.IncludeBlogs = true; sisi.IncludeForums = true; sisi.IncludeMessageCommunication = true; sisi.ClassNames = ""; // for all document types sisi.Path = "/%"; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ID = Guid.NewGuid();
// Save index settings SearchIndexSettings sis = new SearchIndexSettings(); sis.SetSearchIndexSettingsInfo(sisi); sii.IndexSettings = sis;
// Save to database SearchIndexInfoProvider.SetSearchIndexInfo(sii);
// Add current culture to index SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, CMSContext.CurrentDocumentCulture.CultureID);
// Add current site to index SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, CMSContext.CurrentSiteID); |
The following sample code shows how you can rebuild an existing search index:
[C#]
using CMS.SiteProvider;
...
// Get index object from database by index code name SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo("TestIndex");
// If index exists if (sii != null) { // Create rebuild task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } |
The following sample code shows how you can delete an existing search index:
[C#]
using CMS.SiteProvider;
...
// Get index object from database SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo("TestIndex");
// If index exists if (sii != null) { // Delete from database SearchIndexInfoProvider.DeleteSearchIndexInfo(sii); } |
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_managing_search_indexes.htm