The following example creates a smart search index.
privatevoid CreateSearchIndex() { // Create new search index object SearchIndexInfo newIndex = newSearchIndexInfo(); // Set the properties newIndex.IndexDisplayName = "My new index"; newIndex.IndexName = "MyNewIndex"; newIndex.IndexIsCommunityGroup = false; newIndex.IndexType = PredefinedObjectType.DOCUMENT; newIndex.IndexAnalyzerType = AnalyzerTypeEnum.StandardAnalyzer; newIndex.StopWordsFile = ""; // Save the search index SearchIndexInfoProvider.SetSearchIndexInfo(newIndex); }
The following example creates and configures the settings of a search index.
privatebool CreateIndexSettings() {
// Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
if (index != null) { // Create new index settings SearchIndexSettingsInfo indexSettings = newSearchIndexSettingsInfo(); // Set setting properties indexSettings.IncludeBlogs = true; indexSettings.IncludeForums = true; indexSettings.IncludeMessageCommunication = true; indexSettings.ClassNames = ""; // for all document types indexSettings.Path = "/%"; indexSettings.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; indexSettings.ID = Guid.NewGuid(); // Save index settings SearchIndexSettings settings = newSearchIndexSettings(); settings.SetSearchIndexSettingsInfo(indexSettings); index.IndexSettings = settings; // Save to database SearchIndexInfoProvider.SetSearchIndexInfo(index); returntrue; } returnfalse; }
The following example gets and updates a search index.
privatebool GetAndUpdateSearchIndex() {
// Get the search index SearchIndexInfo updateIndex = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
if (updateIndex != null) { // Update the properties updateIndex.IndexDisplayName = updateIndex.IndexDisplayName.ToLower(); // Save the changes SearchIndexInfoProvider.SetSearchIndexInfo(updateIndex); returntrue; } returnfalse; }
The following example gets and bulk updates search indexes.
privatebool GetAndBulkUpdateSearchIndexes() { // Prepare the parameters string where = "IndexName LIKE N'MyNewIndex%'"; // Get the data DataSet indexes = SearchIndexInfoProvider.GetSearchIndexes(where, null); if (!DataHelper.DataSourceIsEmpty(indexes)) { // Loop through the individual items foreach (DataRow indexDr in indexes.Tables[0].Rows) { // Create object from DataRow SearchIndexInfo modifyIndex = newSearchIndexInfo(indexDr);
// Update the properties modifyIndex.IndexDisplayName = modifyIndex.IndexDisplayName.ToUpper();
// Save the changes SearchIndexInfoProvider.SetSearchIndexInfo(modifyIndex); } returntrue; } returnfalse; }
The following example deletes a search index.
privatebool DeleteSearchIndex() {
// Get the search index SearchIndexInfo deleteIndex = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
// Delete the search index SearchIndexInfoProvider.DeleteSearchIndexInfo(deleteIndex); return (deleteIndex != null); }