/// <summary> /// Unigrid on action handler. /// </summary> private void UniGrid_OnAction(string actionName, object actionArgument) { Guid guid; switch (actionName) { case "edit": guid = ValidationHelper.GetGuid(actionArgument, Guid.Empty); RaiseOnAction("edit", guid); break; case "delete": // Delete search index info object from database with it's dependences guid = ValidationHelper.GetGuid(actionArgument, Guid.Empty); sis = sii.IndexSettings; sis.DeleteSearchIndexSettingsInfo(guid); sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Show message about rebuilding index if (smartSearchEnabled) { DataSet result = sii.IndexSettings.GetAll(); if (!DataHelper.DataSourceIsEmpty(result)) { ShowInformation(String.Format(GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>")); } } break; } }
/// <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; } }
private void Update_After(object sender, ObjectEventArgs e) { if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX)) { return; } var fileInfo = e.Object as MediaFileInfo; if (fileInfo == null) { return; } var taskInfo = new SearchTaskInfo { SearchTaskObjectType = SearchHelper.INDEX_TYPE, SearchTaskValue = fileInfo.FileID.ToString(), SearchTaskPriority = 0, SearchTaskType = SearchTaskTypeEnum.Update, SearchTaskStatus = SearchTaskStatusEnum.Ready }; SearchTaskInfoProvider.SetSearchTaskInfo(taskInfo); }
/// <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()); } }
/// <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); }
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")); } } }
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> /// 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; } }
/// <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> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> void Control_OnAction(string actionName, object actionArgument) { switch (actionName) { case "edit": break; case "delete": // Delete search index info object from database with it's dependencies SearchIndexInfoProvider.DeleteSearchIndexInfo(Convert.ToInt32(actionArgument)); break; case "rebuild": if (SearchIndexInfoProvider.SearchEnabled) { int indexID = ValidationHelper.GetInteger(actionArgument, 0); if (SearchHelper.CreateRebuildTask(indexID)) { Control.ShowInformation(Control.GetString("srch.index.rebuildstarted")); // Sleep Thread.Sleep(100); } else { Control.ShowError(Control.GetString("index.nocontent")); } } else { Control.ShowError(Control.GetString("srch.index.searchdisabled")); } break; } }
/// <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> /// 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> /// 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()); } }
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; } }
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(); } }
/// <summary> /// Resets all boxes. /// </summary> public void ResetControls() { txtCodeName.Text = null; txtDisplayName.Text = null; //Fill drop down list DataHelper.FillWithEnum <AnalyzerTypeEnum>(drpAnalyzer, "srch.index.", SearchIndexInfoProvider.AnalyzerEnumToString, true); drpAnalyzer.SelectedValue = SearchIndexInfoProvider.AnalyzerEnumToString(AnalyzerTypeEnum.StandardAnalyzer); chkAddIndexToCurrentSite.Checked = true; // Create sorted list for drop down values SortedList sortedList = new SortedList(); sortedList.Add(GetString("srch.index.doctype"), PredefinedObjectType.DOCUMENT); // Allow forum only if module is available if ((ModuleEntry.IsModuleRegistered(ModuleEntry.FORUMS) && ModuleEntry.IsModuleLoaded(ModuleEntry.FORUMS))) { sortedList.Add(GetString("srch.index.forumtype"), PredefinedObjectType.FORUM); } sortedList.Add(GetString("srch.index.usertype"), PredefinedObjectType.USER); sortedList.Add(GetString("srch.index.customtabletype"), SettingsObjectType.CUSTOMTABLE); sortedList.Add(GetString("srch.index.customsearch"), SearchHelper.CUSTOM_SEARCH_INDEX); sortedList.Add(GetString("srch.index.doctypecrawler"), SearchHelper.DOCUMENTS_CRAWLER_INDEX); sortedList.Add(GetString("srch.index.general"), SearchHelper.GENERALINDEX); drpType.DataValueField = "value"; drpType.DataTextField = "key"; drpType.DataSource = sortedList; drpType.DataBind(); // Pre-select documents index drpType.SelectedValue = PredefinedObjectType.DOCUMENT; }
/// <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> /// Handles the event that occurs when link button "click here" is clicked. /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event argument</param> private void RebuildSiteIndex(object sender, EventArgs e) { // Rebuild search index if (SearchIndexInfoProvider.SearchEnabled) { SearchIndexInfoProvider.RebuildSiteIndexes(siteInfo.SiteID); Control.ShowInformation(ResHelper.GetString("srch.index.rebuildstarted")); } }
// 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)); }
/// <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); }
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; }
public IEnumerable <DataRow> Search(string phrase, string indexName, string path, int results, bool checkPermissions) { var index = SearchIndexInfoProvider.GetSearchIndexInfo(indexName); if (index == null) { yield break; } var searchText = string.Format("+({0})", phrase); var culture = LocalizationContext.CurrentCulture.CultureCode; var documentSearchCondition = new DocumentSearchCondition { Culture = culture }; var condition = new SearchCondition(documentCondition: documentSearchCondition); searchText = SearchSyntaxHelper.CombineSearchCondition(searchText, condition); SearchParameters parameters = new SearchParameters() { SearchFor = searchText, SearchSort = "##SCORE##", Path = path, CurrentCulture = culture, DefaultCulture = null, CombineWithDefaultCulture = false, CheckPermissions = checkPermissions, SearchInAttachments = false, User = (UserInfo)MembershipContext.AuthenticatedUser, SearchIndexes = index.IndexName, StartingPosition = 0, DisplayResults = results, NumberOfProcessedResults = 5000, NumberOfResults = results, AttachmentWhere = String.Empty, AttachmentOrderBy = String.Empty, }; var dataset = CacheHelper.Cache <DataSet>(() => SearchHelper.Search(parameters), new CacheSettings(1, $"search|{indexName}|{path}|{phrase}|{results}|{checkPermissions}|{culture}")); if (dataset != null) { foreach (DataTable table in dataset.Tables) { foreach (DataRow dr in table.Rows) { yield return(dr); } } } }
/// <summary> /// Returns initialized <see cref="SearchServiceClient"/> based on index name "sample-dancinggoat-coffee-azure". /// </summary> private ISearchIndexClient GetSearchClient() { var indexName = NamingHelper.GetValidIndexName("sample-dancinggoat-coffee-azure"); var indexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(indexName); if (indexInfo == null) { return(null); } var serviveClient = new SearchServiceClient(indexInfo.IndexSearchServiceName, new SearchCredentials(indexInfo.IndexAdminKey)); return(serviveClient.Indexes.GetClient(indexName)); }
/// <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 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> /// 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> /// 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); }
private void Delete_After(object sender, ObjectEventArgs e) { if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX)) { return; } var fileInfo = e.Object as MediaFileInfo; if (fileInfo == null) { return; } SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Delete, CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX, SearchFieldsConstants.ID, fileInfo.FileID.ToString(), 0); }
/// <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); }