/// <summary>
    /// Saves changes in site assignment.
    /// </summary>
    protected void SaveIndexes()
    {
        // Check permissions
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Remove old items
        string newValues = ValidationHelper.GetString(usSites.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Unassign site from index
                    SearchIndexSiteInfoProvider.DeleteSearchIndexSiteInfo(indexId, siteId);
                }
            }
        }


        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Assign site to index
                    SearchIndexSiteInfoProvider.AddSearchIndexToSite(indexId, siteId);
                }
            }
        }

        // Show saved message with rebuild link
        ShowChangesSaved();
        ShowInformation(String.Format(GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>"));
    }
Exemplo n.º 2
0
    /// <summary>
    /// Saves changes in site assignment.
    /// </summary>
    protected void SaveIndexes()
    {
        // Check permissions
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Remove old items
        string newValues = ValidationHelper.GetString(usSites.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Unassign site from index
                    SearchIndexSiteInfoProvider.DeleteSearchIndexSiteInfo(indexId, siteId);
                }
            }
        }


        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    // Assign site to index
                    SearchIndexSiteInfoProvider.AddSearchIndexToSite(indexId, siteId);
                }
            }
        }

        // Show saved message with rebuild link
        lblInfo.Visible = true;
    }
    /// <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);
    }
Exemplo n.º 4
0
    /// <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);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Adds search index to site. Called when the "Add index to site" button is pressed.
    /// Expects the CreateSearchIndex method to be run first.
    /// </summary>
    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);
    }
Exemplo n.º 6
0
    /// <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;
            sii.IndexProvider         = SearchIndexInfo.LUCENE_SEARCH_PROVIDER;

            // 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);
            }
        }
    }
    /// <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.GetDocumentName();

        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     = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType             = PredefinedObjectType.FORUM;
            sii.IndexIsCommunityGroup = false;
            sii.IndexProvider         = SearchIndexInfo.LUCENE_SEARCH_PROVIDER;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID         = Guid.NewGuid();
            sisi.Type       = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.SiteName   = SiteContext.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);

            // Assign to current website and current culture
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
            CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);
            SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);
        }
    }
    /// <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);
        }
    }