public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); if (sii.IndexType.Equals(Treenode.OBJECT_TYPE, StringComparison.OrdinalIgnoreCase) || (sii.IndexType == SearchHelper.DOCUMENTS_CRAWLER_INDEX)) { if (!SearchIndexCultureInfoProvider.SearchIndexHasAnyCulture(sii.IndexID)) { ShowError(GetString("index.noculture")); return; } if (!SearchIndexSiteInfoProvider.SearchIndexHasAnySite(sii.IndexID)) { ShowError(GetString("index.nosite")); return; } } if (SearchHelper.CreateRebuildTask(ItemID)) { ShowInformation(GetString("srch.index.rebuildstarted")); } else { ShowError(GetString("index.nocontent")); } } }
public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Get search index info SearchIndexInfo sii = null; if (this.ItemID > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; // Reload info panel System.Threading.Thread.Sleep(100); ReloadInfoPanel(); } }
private static void RebuildIndex(SearchIndexInfo index) { try { // After installation or deployment the index is new but no web farm task is issued // to rebuild the index. This will ensure that index is rebuilt on instance upon first request. if (index.IndexStatusLocal == IndexStatusEnum.NEW) { var taskCreationParameters = new SearchTaskCreationParameters { TaskType = SearchTaskTypeEnum.Rebuild, TaskValue = index.IndexName, RelatedObjectID = index.IndexID }; taskCreationParameters.TargetServers.Add(WebFarmHelper.ServerName); SearchTaskInfoProvider.CreateTask(taskCreationParameters, true); } } catch (SearchIndexException ex) { Service.Resolve <IEventLogService>().LogException("SmartSearch", "INDEX REBUILD", ex); } }
/// <summary> /// Loads drop-down lists. /// </summary> private void LoadDropDowns() { // Init operands if (drpLanguage.Items.Count == 0) { drpLanguage.Items.Add(new ListItem(GetString("transman.translatedto"), "=")); drpLanguage.Items.Add(new ListItem(GetString("transman.nottranslatedto"), "<>")); } // Get site indexes DataSet ds = SearchIndexSiteInfoProvider.GetIndexSites("IndexId", "IndexSiteID = " + CMSContext.CurrentSiteID + " AND IndexID IN (SELECT IndexID FROM CMS_SearchIndex WHERE IndexType = N'" + PredefinedObjectType.DOCUMENT + "')", null, 0); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ValidationHelper.GetInteger(dr["IndexId"], 0)); if ((sii != null) && (sii.IndexType == PredefinedObjectType.DOCUMENT)) { drpIndexes.Items.Add(new ListItem(sii.IndexDisplayName, sii.IndexName)); } } } drpIndexes.Items.Insert(0, new ListItem(GetString("search.sqlsearch"), SQL)); // Init Search for drop down list DataHelper.FillListControlWithEnum(typeof(SearchModeEnum), drpSearchMode, "srch.dialog.", SearchHelper.GetSearchModeString); drpSearchMode.SelectedValue = QueryHelper.GetString("searchmode", SearchHelper.GetSearchModeString(SearchModeEnum.AnyWord)); }
/// <summary> /// Handles click on rebuild link (after sites are saved). /// </summary> /// <param name="eventArgument"></param> public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Check permissions if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY)) { RedirectToAccessDenied("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY); } // Get search index info SearchIndexInfo sii = null; if (this.indexId > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.indexId); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
/// <summary> /// Renders search results into HTML string. /// </summary> private string RenderResults(List <SearchResultItem> results, string searchText) { if (results == null || results.Count == 0) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); var indexCategories = new Dictionary <string, IEnumerable <SearchResultItem> >(StringComparer.InvariantCultureIgnoreCase); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (SearchResultItem resultItem in results) { string index = resultItem.Index; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, results.Where(item => String.Equals(item.Index, index, StringComparison.InvariantCultureIgnoreCase))); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", results); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = TransformationHelper.LoadTransformation(this, PredictiveSearchResultItemTransformationName); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, CreateSearchUrl(searchText))); } return(stringWriter.ToString()); } }
public void RaisePostBackEvent(string eventArgument) { // Rebuild search index if (SearchIndexInfoProvider.SearchEnabled) { SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId); if (si != null) { // Get all indexes depending on given site DataSet result = SearchIndexSiteInfoProvider.GetSiteSearchIndexes(si.SiteID); if (!DataHelper.DataSourceIsEmpty(result)) { List <string> items = new List <string>(); SearchIndexInfo sii = null; // Add all indexes to rebuild queue foreach (DataRow dr in result.Tables[0].Rows) { sii = SearchIndexInfoProvider.GetSearchIndexInfo((int)dr["IndexID"]); if (sii != null) { items.Add(sii.IndexName); } } // Rebuild all indexes SearchTaskInfoProvider.CreateMultiTask(SearchTaskTypeEnum.Rebuild, null, null, items, true); } } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
/// <summary> /// Reloads datagrid. /// </summary> private void Reload() { UniGrid.OnExternalDataBound += new OnExternalDataBoundEventHandler(UniGrid_OnExternalDataBound); UniGrid.OnAction += new OnActionEventHandler(UniGrid_OnAction); UniGrid.HideControlForZeroRows = true; sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); if (sii != null) { DataSet result = sii.IndexSettings.GetAll(); if (!DataHelper.DataSourceIsEmpty(result)) { // Set 'id' column to first position if (result.Tables[0].Columns["id"] != null) { result.Tables[0].Columns["id"].SetOrdinal(0); } // Check if 'type' column exists if (result.Tables[0].Columns["type"] == null) { result.Tables[0].Columns.Add(new DataColumn("type")); } } UniGrid.DataSource = result; UniGrid.ReloadData(); } }
/// <summary> /// Resets all boxes. /// </summary> public void LoadControls() { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); // If we are editing existing search index if (sii != null) { SearchIndexSettings sis = new SearchIndexSettings(); sis.LoadData(sii.IndexSettings.GetData()); SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(ItemGUID); if (sisi != null) { if (!RequestHelper.IsPostBack()) { selSite.Value = sisi.SiteName; selForum.SetValue("SiteName", sisi.SiteName); selForum.Value = sisi.ForumNames; } ItemType = sisi.Type; } } plcForumsInfo.Visible = true; if (ItemType == SearchIndexSettingsInfo.TYPE_EXLUDED) { plcForumsInfo.Visible = false; } }
/// <summary> /// Resets all boxes. /// </summary> public void LoadControls() { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); // If we are editing existing search index if (sii != null) { SearchIndexSettings sis = new SearchIndexSettings(); sis.LoadData(sii.IndexSettings.GetData()); SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(ItemGUID); if (sisi != null) { selectClassnames.Value = sisi.ClassNames; selectpath.Value = sisi.Path; ItemType = sisi.Type; if (sisi.Type == SearchIndexSettingsInfo.TYPE_ALLOWED) { chkInclForums.Checked = sisi.IncludeForums; chkInclBlog.Checked = sisi.IncludeBlogs; chkInclBoards.Checked = sisi.IncludeMessageCommunication; chkInclCats.Checked = sisi.IncludeCategories; chkInclAtt.Checked = sisi.IncludeAttachments; } } } // Hide appropriate controls for excluded item if ((ItemType == SearchIndexSettingsInfo.TYPE_EXLUDED) || ((sii != null) && (sii.IndexType == SearchHelper.DOCUMENTS_CRAWLER_INDEX))) { pnlAllowed.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { // Disable textbox editing selectInRole.UseFriendlyMode = true; selectNotInRole.UseFriendlyMode = true; if (!RequestHelper.IsPostBack()) { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); if (sii != null) { SearchIndexSettings sis = sii.IndexSettings; SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(SearchHelper.SIMPLE_ITEM_ID); // Create new if (sisi != null) { chkHidden.Checked = ValidationHelper.GetBoolean(sisi.GetValue("UserHidden"), false); chkOnlyEnabled.Checked = ValidationHelper.GetBoolean(sisi.GetValue("UserEnabled"), true); chkSite.Checked = ValidationHelper.GetBoolean(sisi.GetValue("UserAllSites"), false); selectInRole.Value = ValidationHelper.GetString(sisi.GetValue("UserInRoles"), String.Empty); selectNotInRole.Value = ValidationHelper.GetString(sisi.GetValue("UserNotInRoles"), String.Empty); txtWhere.TextArea.Text = sisi.WhereCondition; } } } }
/// <summary> /// Creates index settings. Called when the "Create index settings" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool CreateIndexSettings() { // Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex"); if (index != null) { // Create new index settings SearchIndexSettingsInfo indexSettings = new SearchIndexSettingsInfo(); // 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 = new SearchIndexSettings(); settings.SetSearchIndexSettingsInfo(indexSettings); index.IndexSettings = settings; // Save to database SearchIndexInfoProvider.SetSearchIndexInfo(index); return(true); } return(false); }
/// <summary> /// Gets and bulk updates search indexes. Called when the "Get and bulk update indexes" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool 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 = new SearchIndexInfo(indexDr); // Update the properties modifyIndex.IndexDisplayName = modifyIndex.IndexDisplayName.ToUpper(); // Save the changes SearchIndexInfoProvider.SetSearchIndexInfo(modifyIndex); } return(true); } return(false); }
/// <summary> /// Renders search results into HTML string. /// </summary> private string RenderResults(DataSet results, string searchText) { if (results == null) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); IDictionary <string, DataView> indexCategories = new Dictionary <string, DataView>(StringComparer.InvariantCultureIgnoreCase); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (DataRow row in results.Tables["results"].Rows) { string index = (string)row["index"]; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, new DataView(results.Tables["results"], "index = '" + index + "'", "", DataViewRowState.CurrentRows)); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", new DataView(results.Tables["results"])); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = TransformationHelper.LoadTransformation(this, PredictiveSearchResultItemTransformationName); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Tables["results"].Rows.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, CreateSearchUrl(searchText))); } return(stringWriter.ToString()); } }
/// <summary> /// Renders search results into HTML string. /// </summary> private static string RenderResults(DataSet results, string searchText, string PredictiveSearchNoResultsContent, bool PredictiveSearchDisplayCategories, int PredictiveSearchMaxResults, string PredictiveSearchResultItemTransformationName, string PredictiveSearchMoreResultsContent, string searchURL) { if (results == null) { // No results return(String.IsNullOrEmpty(PredictiveSearchNoResultsContent) ? "" : "<div class='nonSelectable'>" + PredictiveSearchNoResultsContent + "</div>"); } else { UIRepeater repSearchResults = new UIRepeater(); IDictionary <string, DataView> indexCategories = new Dictionary <string, DataView>(); StringWriter stringWriter = new StringWriter(); // Display categories - create DataView for each index if (PredictiveSearchDisplayCategories) { foreach (DataRow row in results.Tables["results"].Rows) { string index = (string)row["index"]; if (!indexCategories.ContainsKey(index)) { indexCategories.Add(index, new DataView(results.Tables["results"], "index = '" + index + "'", "", DataViewRowState.CurrentRows)); } } } // Do not display categories - create DataView of whole table else { indexCategories.Add("results", new DataView(results.Tables["results"])); } // Render each index category foreach (var categories in indexCategories) { // Display categories if (PredictiveSearchDisplayCategories) { SearchIndexInfo indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(categories.Key); string categoryName = indexInfo == null ? String.Empty : indexInfo.IndexDisplayName; repSearchResults.HeaderTemplate = new TextTransformationTemplate("<div class='predictiveSearchCategory nonSelectable'>" + categoryName + "</div>"); } // Fill repeater with results repSearchResults.ItemTemplate = new TextTransformationTemplate(CacheHelper.Cache(cs => CMS.PortalEngine.TransformationInfoProvider.GetTransformation(PredictiveSearchResultItemTransformationName), new CacheSettings(60, PredictiveSearchResultItemTransformationName)).TransformationCode); repSearchResults.DataSource = categories.Value; repSearchResults.DataBind(); repSearchResults.RenderControl(new HtmlTextWriter(stringWriter)); } // More results if (PredictiveSearchMaxResults == results.Tables["results"].Rows.Count) { stringWriter.Write(String.Format(PredictiveSearchMoreResultsContent, URLHelper.UpdateParameterInUrl(searchURL, "searchtext", HttpUtility.UrlEncode(searchText)))); } return(stringWriter.ToString()); } }
/// <summary> /// Perform search. /// </summary> protected override void OnPreRender(EventArgs e) { // Check whether current request is not postback if (!RequestHelper.IsPostBack()) { // Get current search text from query string string searchText = QueryHelper.GetString("searchtext", ""); // Check whether search text is defined if (!string.IsNullOrEmpty(searchText)) { // Get current search mode from query string string searchMode = QueryHelper.GetString("searchmode", ""); CMS.ISearchEngine.SearchModeEnum searchModeEnum = ISearchHelper.GetSearchModeEnum(searchMode); // Get current index id int indexId = QueryHelper.GetInteger("indexId", 0); // Get current index info object SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); // Check whether index info exists if (sii != null) { // Keep search text in search textbox //txtSearchFor.Text = searchText; searchText = SearchHelper.CombineSearchCondition(searchText, null, searchModeEnum, SearchOptionsEnum.FullSearch, null, null, null, false); // Get positions and ranges for search method int startPosition = 0; int numberOfProceeded = 100; int displayResults = 100; int numberOfResults = 0; if (pgrSearch.PageSize != 0 && pgrSearch.GroupSize != 0) { startPosition = (pgrSearch.CurrentPage - 1) * pgrSearch.PageSize; numberOfProceeded = (((pgrSearch.CurrentPage / pgrSearch.GroupSize) + 1) * pgrSearch.PageSize * pgrSearch.GroupSize) + pgrSearch.PageSize; displayResults = pgrSearch.PageSize; } // Search DataSet results = SearchHelper.Search(searchText, null, null, null, "##ALL##", null, false, false, false, sii.IndexName, displayResults, startPosition, numberOfProceeded, (UserInfo)CMSContext.CurrentUser, out numberOfResults, null, null); // Fill repeater with results repSearchResults.DataSource = results; repSearchResults.PagerForceNumberOfResults = numberOfResults; repSearchResults.DataBind(); // Show now results found ? if (numberOfResults == 0) { lblNoResults.Text = "<br />" + GetString("srch.results.noresults"); lblNoResults.Visible = true; } } } } base.OnPreRender(e); }
/// <summary> /// Deletes search index. Called when the "Delete index" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool DeleteSearchIndex() { // Get the search index SearchIndexInfo deleteIndex = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex"); // Delete the search index SearchIndexInfoProvider.DeleteSearchIndexInfo(deleteIndex); return(deleteIndex != null); }
// Returns an initialized 'SearchServiceClient' instance for the specified index private static ISearchIndexClient InitializeIndex(string indexCodeName) { // Converts the Xperience index code name to a valid Azure Search index name (if necessary) indexCodeName = NamingHelper.GetValidIndexName(indexCodeName); SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo(indexCodeName); SearchServiceClient client = new SearchServiceClient(index.IndexSearchServiceName, new SearchCredentials(index.IndexAdminKey)); return(client.Indexes.GetClient(indexCodeName)); }
protected void Page_Load(object sender, EventArgs e) { // Get search index info object SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); if (sii != null) { // If doesn't exist select default type indexType = sii.IndexType; } ContentEdit.Visible = false; forumEdit.Visible = false; customTableEdit.Visible = false; ContentEdit.StopProcessing = true; forumEdit.StopProcessing = true; customTableEdit.StopProcessing = true; // Set tabs according to index type switch (indexType) { case PredefinedObjectType.DOCUMENT: case SearchHelper.DOCUMENTS_CRAWLER_INDEX: // Document index ContentEdit.ItemID = indexId; ContentEdit.ItemGUID = itemGuid; ContentEdit.Visible = true; ContentEdit.StopProcessing = false; break; case PredefinedObjectType.FORUM: // Forum index type forumEdit.ItemID = indexId; forumEdit.ItemGUID = itemGuid; forumEdit.Visible = true; forumEdit.StopProcessing = false; break; case SettingsObjectType.CUSTOMTABLE: // Custom table index customTableEdit.ItemID = indexId; customTableEdit.ItemGUID = itemGuid; customTableEdit.Visible = true; customTableEdit.StopProcessing = false; break; } ContentEdit.ItemType = itemType; forumEdit.ItemType = itemType; }
/// <summary> /// Rebuilds the search index. Called when the "Rebuild index" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool RebuildIndex() { // Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex"); if (index != null) { // Create rebuild task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, index.IndexType, null, index.IndexName); return(true); } return(false); }
/// <summary> /// Creates content search index. /// </summary> /// <param name="group">Particular group info object</param> private void CreateGroupContentSearchIndex(GroupInfo group) { string codeName = "default_group_" + group.GroupGUID; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; const string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, string.Empty) + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = TreeNode.OBJECT_TYPE; sii.IndexIsCommunityGroup = false; sii.IndexProvider = SearchIndexInfo.LUCENE_SEARCH_PROVIDER; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = mGroupTemplateTargetAliasPath + "/" + group.GroupName + "/%"; sisi.SiteName = SiteContext.CurrentSiteName; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assign to current website and current culture SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); CultureInfo ci = DocumentContext.CurrentDocumentCulture; if (ci != null) { SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); } // Register rebuild index action SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID); } }
/// <summary> /// Creates or rebuild department content search index. /// </summary> /// <param name="departmentNode">Department node</param> private void CreateDepartmentContentSearchIndex(TreeNode departmentNode) { string codeName = "default_department_" + departmentNode.NodeGUID; string departmentName = departmentNode.GetDocumentName(); SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = TreeNode.OBJECT_TYPE; sii.IndexIsCommunityGroup = false; sii.IndexProvider = SearchIndexInfo.LUCENE_SEARCH_PROVIDER; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = departmentNode.NodeAliasPath + "/%"; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assign to current website SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); } // Add current culture to search index CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture); SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); // Rebuild search index SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID); }
/// <summary> /// On external databound. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> object Control_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { // Get index status case "indexstatus": int indexID = ValidationHelper.GetInteger(parameter, 0); SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexID); if (sii != null) { var status = (sii.IndexFilesStatus == IndexStatusEnum.READY) && sii.IndexIsOutdated ? "srch.status.readybutoutdated" : "srch.status." + sii.IndexFilesStatus; return(Control.GetString(status)); } break; case "indextype": string type = ValidationHelper.GetString(parameter, String.Empty); return(Control.GetString("smartsearch.indextype." + type.ToLowerCSafe())); } // Disable all actions if (disableActions) { CMSGridActionButton button = null; switch (sourceName.ToLowerCSafe()) { case "edit": button = ((CMSGridActionButton)sender); button.Enabled = false; break; case "delete": button = ((CMSGridActionButton)sender); button.Enabled = false; break; case "rebuild": button = ((CMSGridActionButton)sender); button.Enabled = false; break; } } return(null); }
/// <summary> /// Adds culture to search index. Called when the "Add culture to index" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool AddCultureToSearchIndex() { // Get the search index and culture SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex"); CultureInfo culture = CultureInfoProvider.GetCultureInfo("en-us"); if ((index != null) && (culture != null)) { // Save the binding SearchIndexCultureInfoProvider.AddSearchIndexCulture(index.IndexID, culture.CultureID); return(true); } return(false); }
protected void btnOk_Click(object sender, EventArgs e) { string errorMessage = new Validator().NotEmpty(txtAssembly.Text.Trim(), GetString("srch.index.assemblyempty")).NotEmpty(txtClassName.Text.Trim(), GetString("srch.index.classnameempty")).Result; if (String.IsNullOrEmpty(errorMessage)) { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); if (sii != null) { SearchIndexSettings sis = sii.IndexSettings; SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(SearchHelper.CUSTOM_INDEX_DATA); // Create new if (sisi == null) { sisi = new SearchIndexSettingsInfo(); sisi.ID = SearchHelper.CUSTOM_INDEX_DATA; } sisi.SetValue("AssemblyName", txtAssembly.Text.Trim()); sisi.SetValue("ClassName", txtClassName.Text.Trim()); sisi.SetValue("CustomData", txtData.TextArea.Text); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Redirect to edit mode lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); if (smartSearchEnabled) { lblInfo.Text += " " + String.Format(GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>"); } } } else { lblError.Visible = true; lblError.Text = errorMessage; return; } }
/// <summary> /// Resets all boxes. /// </summary> public void LoadControls() { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID); // If we are editing existing search index if (sii != null) { SearchIndexSettings sis = new SearchIndexSettings(); sis.LoadData(sii.IndexSettings.GetData()); SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(this.ItemGUID); if (sisi != null) { customTableSelector.Value = sisi.ClassNames; txtWhere.TextArea.Text = sisi.WhereCondition; } } }
/// <summary> /// Resets all boxes. /// </summary> public void LoadControls() { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); string siteWhere = String.Empty; // Load only those site to which the index is assigned var siteIDs = SearchIndexSiteInfoProvider.GetIndexSiteBindings(ItemID).Column("IndexSiteID").Select(X => X.IndexSiteID.ToString()).ToList(); if (siteIDs.Count > 0) { siteWhere = SqlHelper.GetWhereCondition <string>("SiteID", siteIDs, false); // Preselect current site if it is assigned to index if (!RequestHelper.IsPostBack() && siteIDs.Contains(SiteContext.CurrentSiteID.ToString())) { selSite.Value = SiteContext.CurrentSiteName; } selSite.UniSelector.WhereCondition = siteWhere; selSite.Reload(false); } else { pnlForm.Visible = false; ShowError(GetString("srch.index.nositeselected")); } // If we are editing existing search index if (sii != null) { SearchIndexSettings sis = new SearchIndexSettings(); sis.LoadData(sii.IndexSettings.GetData()); SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(ItemGUID); if (sisi != null) { selectForm.Value = ValidationHelper.GetString(sisi.GetValue("FormName"), ""); txtWhere.TextArea.Text = sisi.WhereCondition; selSite.Value = sisi.SiteName; } } // Init controls SetControlsStatus(false); }
protected void btnOk_Click(object sender, EventArgs e) { // Validate - check for selected object name if (string.IsNullOrEmpty(selObjects.Value.ToString())) { lblError.Visible = true; return; } SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID); if (sii != null) { SearchIndexSettings sis = sii.IndexSettings; SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(SearchHelper.SIMPLE_ITEM_ID); // Create new if (sisi == null) { sisi = new SearchIndexSettingsInfo(); sisi.ID = SearchHelper.SIMPLE_ITEM_ID; } sisi.ClassNames = ValidationHelper.GetString(selObjects.Value, String.Empty); sisi.WhereCondition = txtWhere.TextArea.Text.Trim(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); selObjects.ShowPleaseSelect = false; selObjects.Reload(true); // Display a message lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); if (smartSearchEnabled) { lblInfo.Text += " " + String.Format(GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>"); } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { int indexId = QueryHelper.GetInteger("indexid", 0); IndexID = 0; // Get the IndexInfo in order to obtain the ClassID which the index contains. SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); if ((sii != null) && (sii.IndexSettings != null)) { // Get the index settings Dictionary <Guid, SearchIndexSettingsInfo> settingsItems = sii.IndexSettings.Items; if (settingsItems.ContainsKey(SearchHelper.SIMPLE_ITEM_ID)) { // Get the ClassInfo and set the ClassID to the searchFields control string className = settingsItems[SearchHelper.SIMPLE_ITEM_ID].ClassNames.ToLowerCSafe(); if (sii.IndexType == SearchHelper.GENERALINDEX) { var info = ModuleManager.GetReadOnlyObject(className); if (info != null) { className = info.TypeInfo.ObjectClassName; } } DataClassInfo classInfo = DataClassInfoProvider.GetDataClassInfo(className); if (classInfo != null) { IndexID = sii.IndexID; searchFields.ItemID = classInfo.ClassID; } } else { // ClassName not defined yet, display a message directing the user to the Index tab ShowInformation(GetString("srch.index.required")); searchFields.Visible = false; } } // Setup the searchFields control searchFields.LoadActualValues = true; searchFields.OnSaved += new EventHandler(searchFields_OnSaved); }
/// <summary> /// Creates search index. Called when the "Create index" button is pressed. /// </summary> private bool CreateSearchIndex() { // Create new search index object SearchIndexInfo newIndex = new SearchIndexInfo(); // 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); return(true); }
protected void Page_Load(object sender, EventArgs e) { if (!RequestHelper.IsPostBack()) { SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); if (sii != null) { SearchIndexSettings sis = sii.IndexSettings; SearchIndexSettingsInfo sisi = sis.GetSearchIndexSettingsInfo(SearchHelper.SIMPLE_ITEM_ID); if (sisi != null) { drpObjType.Value = sisi.ClassNames; txtWhere.TextArea.Text = sisi.WhereCondition; } } } }
/// <summary> /// Reloads datagrid. /// </summary> private void Reload() { UniGrid.OnExternalDataBound += new OnExternalDataBoundEventHandler(UniGrid_OnExternalDataBound); UniGrid.OnAction += new OnActionEventHandler(UniGrid_OnAction); UniGrid.ZeroRowsText = GetString("general.nodatafound"); DataSet sorted = null; sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); if (sii != null) { DataSet result = sii.IndexSettings.GetAll(); if (!DataHelper.DataSourceIsEmpty(result)) { // Set 'id' column to first position if (result.Tables[0].Columns["id"] != null) { result.Tables[0].Columns["id"].SetOrdinal(0); } // Check if 'type' column exists if (result.Tables[0].Columns["type"] == null) { result.Tables[0].Columns.Add(new DataColumn("type")); } // Sort result sorted = new DataSet(); sorted.Tables.Add(result.Tables[0].Clone()); if (result.Tables[0].Columns.Contains("classNames")) { foreach (DataRow dr in result.Tables[0].Select(null, "classNames")) { sorted.Tables[0].ImportRow(dr); } } } UniGrid.DataSource = sorted; UniGrid.ReloadData(); } }
public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Get search index info SearchIndexInfo sii = null; if (this.indexId > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.indexId); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
protected void Page_Load(object sender, EventArgs e) { if (this.StopProcessing) { return; } // Show panel with message how to enable indexing if (!smartSearchEnabled) { pnlDisabled.Visible = true; } indexId = QueryHelper.GetInteger("indexid", 0); UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; UniGrid.OnAction += UniGrid_OnAction; UniGrid.OnDataReload += UniGrid_OnDataReload; UniGrid.HideControlForZeroRows = true; UniGrid.ShowActionsMenu = true; UniGrid.AllColumns = "id, ForumNames, SiteName, Type"; sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); }
protected void Page_Load(object sender, EventArgs e) { if (this.StopProcessing) { return; } // Show panel with message how to enable indexing if (!smartSearchEnabled) { pnlDisabled.Visible = true; } UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; UniGrid.OnAction += UniGrid_OnAction; UniGrid.OnDataReload += UniGrid_OnDataReload; UniGrid.ZeroRowsText = GetString("general.nodatafound"); UniGrid.ShowActionsMenu = true; UniGrid.AllColumns = "id, Type, DisplayName, ClassNames, WhereCondition"; indexId = QueryHelper.GetInteger("indexid", 0); sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Show panel with message how to enable indexing if (!SettingsKeyProvider.GetBoolValue("CMSSearchIndexingEnabled")) { pnlDisabled.Visible = true; } // Get file size and document count informations resource strings pnlInfo.GroupingText = GetString("srch.index.info"); // Action buttons imgOptimize.ImageUrl = GetImageUrl("CMSModules/CMS_SMartSearch/optimize.png"); btnOptimize.Text = GetString("srch.index.optimize"); btnOptimize.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("srch.index.confirmoptimize")) + ");"; imgRebuild.ImageUrl = GetImageUrl("CMSModules/CMS_SMartSearch/rebuild.png"); btnRebuild.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("srch.index.confirmrebuild")) + ");"; btnRebuild.Text = GetString("srch.index.rebuild"); // Init controls rfvCodeName.ErrorMessage = GetString("general.requirescodename"); rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname"); rfvBatchSize.ErrorMessage = GetString("general.requiresvalue"); btnOk.Text = GetString("General.OK"); // Possible length of path - already taken, +1 because in MAX_INDEX PATH is count codename of length 1 string indexPath = Path.Combine(SettingsKeyProvider.WebApplicationPhysicalPath, "App_Data\\CMSModules\\SmartSearch\\"); codeNameLength = SearchHelper.MAX_INDEX_PATH - indexPath.Length + 1; pnlContent.Visible = true; txtCodeName.MaxLength = codeNameLength; // Get search index info sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID); // Set edited object if (this.ItemID > 0) { EditedObject = sii; } if (sii != null) { string indexTypeStr = String.Empty; switch (sii.IndexType) { // Documents case PredefinedObjectType.DOCUMENT: indexTypeStr = GetString("srch.index.doctype"); break; // Forums case PredefinedObjectType.FORUM: indexTypeStr = GetString("srch.index.forumtype"); break; // Users case PredefinedObjectType.USER: indexTypeStr = GetString("srch.index.usertype"); break; // Custom tables case SettingsObjectType.CUSTOMTABLE: indexTypeStr = GetString("srch.index.customtabletype"); break; // General index case SearchHelper.GENERALINDEX: indexTypeStr = GetString("srch.index.general"); break; // Custom search index case SearchHelper.CUSTOM_SEARCH_INDEX: indexTypeStr = GetString("srch.index.customsearch"); break; // Documents crawler case SearchHelper.DOCUMENTS_CRAWLER_INDEX: indexTypeStr = GetString("srch.index.doctypecrawler"); break; } lblTypeValue.Text = indexTypeStr; stopCustomControl.IndexInfo = sii; stopCustomControl.AnalyzerDropDown = drpAnalyzer; } if (!RequestHelper.IsPostBack()) { this.LoadControls(); } // Reload info panel ReloadInfoPanel(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Set disabled module info ucDisabledModule.SettingsKeys = "CMSSearchIndexingEnabled"; ucDisabledModule.InfoText = GetString("srch.searchdisabledinfo"); // Get file size and document count information resource strings pnlInfo.GroupingText = GetString("srch.index.info"); // Action buttons InitializeHeaderActions(); // Init controls rfvCodeName.ErrorMessage = GetString("general.requirescodename"); rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname"); rfvBatchSize.ErrorMessage = GetString("general.requiresvalue"); // Possible length of path - already taken, +1 because in MAX_INDEX PATH is count codename of length 1 string indexPath = Path.Combine(SettingsKeyProvider.WebApplicationPhysicalPath, "App_Data\\CMSModules\\SmartSearch\\"); codeNameLength = SearchHelper.MAX_INDEX_PATH - indexPath.Length + 1; pnlContent.Visible = true; txtCodeName.MaxLength = codeNameLength; // Get search index info sii = SearchIndexInfoProvider.GetSearchIndexInfo(ItemID); // Set edited object if (ItemID > 0) { EditedObject = sii; } if (sii != null) { string indexTypeStr = String.Empty; switch (sii.IndexType) { // Documents case PredefinedObjectType.DOCUMENT: indexTypeStr = GetString("srch.index.doctype"); break; // Forums case PredefinedObjectType.FORUM: indexTypeStr = GetString("srch.index.forumtype"); break; // Users case PredefinedObjectType.USER: indexTypeStr = GetString("srch.index.usertype"); break; // Custom tables case SettingsObjectType.CUSTOMTABLE: indexTypeStr = GetString("srch.index.customtabletype"); break; // General index case SearchHelper.GENERALINDEX: indexTypeStr = GetString("srch.index.general"); break; // Custom search index case SearchHelper.CUSTOM_SEARCH_INDEX: indexTypeStr = GetString("srch.index.customsearch"); break; // Documents crawler case SearchHelper.DOCUMENTS_CRAWLER_INDEX: indexTypeStr = GetString("srch.index.doctypecrawler"); break; } lblTypeValue.Text = indexTypeStr; stopCustomControl.IndexInfo = sii; stopCustomControl.AnalyzerDropDown = drpAnalyzer; } if (!RequestHelper.IsPostBack()) { LoadControls(); } // Reload info panel ReloadInfoPanel(); }
/// <summary> /// Creates search index. Called when the "Create index" button is pressed. /// </summary> private bool CreateSearchIndex() { // Create new search index object SearchIndexInfo newIndex = new SearchIndexInfo(); // 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); return true; }
/// <summary> /// Implementation of rebuild method. /// </summary> /// <param name="srchInfo">Search index info</param> public void Rebuild(SearchIndexInfo srchInfo) { EventLogProvider ev = new EventLogProvider(); ev.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "MyCustomIndex", "Rebuild", null, "The index is building"); }
/// <summary> /// Gets and bulk updates search indexes. Called when the "Get and bulk update indexes" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool 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 = new SearchIndexInfo(indexDr); // Update the properties modifyIndex.IndexDisplayName = modifyIndex.IndexDisplayName.ToUpper(); // Save the changes SearchIndexInfoProvider.SetSearchIndexInfo(modifyIndex); } return true; } return false; }
/// <summary> /// Creates content search index. /// </summary> /// <param name="group">Particular group info object</param> private void CreateGroupContentSearchIndex(GroupInfo group) { string codeName = "default_group_" + group.GroupGUID; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; const string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, string.Empty) + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = TreeNode.OBJECT_TYPE; sii.IndexIsCommunityGroup = false; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = mGroupTemplateTargetAliasPath + "/" + group.GroupName + "/%"; sisi.SiteName = SiteContext.CurrentSiteName; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assign to current website and current culture SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); CultureInfo ci = DocumentContext.CurrentDocumentCulture; if (ci != null) { SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); } // Register rebuild index action SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID); } }
/// <summary> /// Creates forum search index. /// </summary> /// <param name="group">Particular group info object</param> private void CreateGroupForumSearchIndex(GroupInfo group) { string codeName = "forums_group_" + group.GroupGUID; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; const string suffix = " - Forums"; sii.IndexDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, string.Empty) + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = PredefinedObjectType.FORUM; sii.IndexIsCommunityGroup = false; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.ForumNames = "*_group_" + group.GroupGUID; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.SiteName = SiteContext.CurrentSiteName; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assing to current website and current culture SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); CultureInfo ci = DocumentContext.CurrentDocumentCulture; if (ci != null) { SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); } } }
protected void Page_Load(object sender, EventArgs e) { // Check "read" permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.SearchIndex", "Read")) { RedirectToAccessDenied("CMS.SearchIndex", "Read"); } indexId = QueryHelper.GetInteger("indexId", 0); string indexListUr = "~/CMSModules/SmartSearch/SearchIndex_List.aspx"; string currentIndex = ""; index = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); if (index != null) { currentIndex = index.IndexDisplayName; } // Initialize PageTitle breadcrumbs string[,] pageTitleTabs = new string[2, 3]; pageTitleTabs[0, 0] = GetString("srch.index.indexes"); pageTitleTabs[0, 1] = indexListUr; pageTitleTabs[0, 2] = "_parent"; pageTitleTabs[1, 0] = currentIndex; pageTitleTabs[1, 1] = ""; pageTitleTabs[1, 2] = ""; CurrentMaster.Title.Breadcrumbs = pageTitleTabs; CurrentMaster.Title.TitleText = GetString("srch.index.indexes"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_SearchIndex/object.png"); CurrentMaster.Title.HelpTopicName = "searchindex_general"; CurrentMaster.Title.HelpName = "title"; // Tabs InitalizeTabs(); }
protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { return; } // Show panel with message how to enable indexing ucDisabledModule.SettingsKeys = "CMSSearchIndexingEnabled"; ucDisabledModule.InfoText = GetString("srch.searchdisabledinfo"); UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; UniGrid.OnAction += UniGrid_OnAction; UniGrid.OnDataReload += UniGrid_OnDataReload; UniGrid.ZeroRowsText = GetString("general.nodatafound"); UniGrid.ShowActionsMenu = true; UniGrid.AllColumns = "id, Type, DisplayName, ClassNames, WhereCondition"; indexId = QueryHelper.GetInteger("indexid", 0); sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Get code name string codeName = txtCodeName.Text.Trim(); // Perform validation string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).Result; // Check CodeName for identifier format if (!ValidationHelper.IsCodeName(codeName)) { errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat"); } // Check length of code name if (codeName.Length > codeNameLength) { errorMessage = GetString("srch.codenameexceeded"); } if (errorMessage == "") { // Create new SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { sii = new SearchIndexInfo(); // Set the fields sii.IndexName = codeName; sii.IndexDisplayName = txtDisplayName.Text.Trim(); sii.IndexAnalyzerType = SearchIndexInfoProvider.AnalyzerCodenameToEnum(drpAnalyzer.SelectedValue); // Community indexing is not yet supported //sii.IndexIsCommunityGroup = chkCommunity.Checked; sii.IndexIsCommunityGroup = false; sii.IndexType = drpType.SelectedValue; sii.CustomAnalyzerAssemblyName = stopCustomControl.CustomAnalyzerAssemblyName; sii.CustomAnalyzerClassName = stopCustomControl.CustomAnalyzerClassName; sii.StopWordsFile = stopCustomControl.StopWordsFile; // Save the object SearchIndexInfoProvider.SetSearchIndexInfo(sii); ItemID = sii.IndexID; // Assign to current website if (chkAddIndexToCurrentSite.Checked) { SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, CMSContext.CurrentSiteID); } // Redirect to edit mode RaiseOnSaved(); } else { // Error message - code name already exists ShowError(GetString("srch.index.codenameexists")); } } else { // Error message - validation ShowError(errorMessage); } }
/// <summary> /// Creates forum search index. /// </summary> /// <param name="departmentNode">Department node</param> private void CreateDepartmentForumSearchIndex(TreeNode departmentNode) { string codeName = "forums_department_" + departmentNode.NodeGUID; string departmentName = departmentNode.DocumentName; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; string suffix = " - Forums"; sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix; sii.IndexAnalyzerType = AnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = PredefinedObjectType.FORUM; sii.IndexIsCommunityGroup = false; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.SiteName = CMSContext.CurrentSiteName; sisi.ForumNames = "*_department_" + departmentNode.NodeGUID; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assing to current website and current culture SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, CMSContext.CurrentSiteID); CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture); SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); } }
/// <summary> /// Creates or rebuild department content search index. /// </summary> /// <param name="departmentNode">Department node</param> private void CreateDepartmentContentSearchIndex(TreeNode departmentNode) { string codeName = "default_department_" + departmentNode.NodeGUID; string departmentName = departmentNode.DocumentName; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix; sii.IndexAnalyzerType = AnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = PredefinedObjectType.DOCUMENT; sii.IndexIsCommunityGroup = false; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = departmentNode.NodeAliasPath + "/%"; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assing to current website SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, CMSContext.CurrentSiteID); } // Add curent culture to search index CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture); SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); // Rebuild search index SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); }