SearchSimilarPages() public static method

Searches for pages with name or title similar to a specified value.
public static SearchSimilarPages ( string name, string nspace ) : System.PageInfo[]
name string The name to look for (null for the root).
nspace string The namespace to search into.
return System.PageInfo[]
Example #1
0
        /// <summary>
        /// Prints the results of the automatic search.
        /// </summary>
        public void PrintSearchResults()
        {
            StringBuilder sb = new StringBuilder(1000);

            PageInfo[] results = SearchTools.SearchSimilarPages(Request["Page"], DetectNamespace());
            if (results.Length > 0)
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.WereYouLookingFor);
                sb.Append("</p>");
                sb.Append("<ul>");
                PageContent c;
                for (int i = 0; i < results.Length; i++)
                {
                    c = Content.GetPageContent(results[i], true);
                    sb.Append(@"<li><a href=""");
                    UrlTools.BuildUrl(sb, Tools.UrlEncode(results[i].FullName), Settings.PageExtension);
                    sb.Append(@""">");
                    sb.Append(FormattingPipeline.PrepareTitle(c.Title, false, FormattingContext.PageContent, c.PageInfo));
                    sb.Append("</a></li>");
                }
                sb.Append("</ul>");
            }
            else
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.NoSimilarPages);
                sb.Append("</p>");
            }
            sb.Append(@"<br /><p>");
            sb.Append(Properties.Messages.YouCanAlso);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Search.aspx?Query=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@""">");
            sb.Append(Properties.Messages.PerformASearch);
            sb.Append("</a> ");
            sb.Append(Properties.Messages.Or);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Edit.aspx?Page=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@"""><b>");
            sb.Append(Properties.Messages.CreateThePage);
            sb.Append("</b></a> (");
            sb.Append(Properties.Messages.CouldRequireLogin);
            sb.Append(").</p>");

            lblSearchResults.Text = sb.ToString();
        }
Example #2
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            lstAvailablePage.Items.Clear();
            btnAddPage.Enabled = false;

            txtPageName.Text = txtPageName.Text.Trim();

            if (txtPageName.Text.Length == 0)
            {
                return;
            }

            PageInfo[] pages = SearchTools.SearchSimilarPages(txtPageName.Text, CurrentNamespace);

            string cp = CurrentProvider;

            foreach (PageInfo page in
                     from p in pages
                     where p.Provider.GetType().FullName == cp
                     select p)
            {
                // Filter pages already in the list
                bool found = false;
                foreach (ListItem item in lstPages.Items)
                {
                    if (item.Value == page.FullName)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    PageContent content = Content.GetPageContent(page, false);
                    lstAvailablePage.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));
                }
            }

            btnAddPage.Enabled = lstAvailablePage.Items.Count > 0;
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            txtPageName.Text = txtPageName.Text.Trim();

            if (txtPageName.Text.Length == 0)
            {
                lstAvailablePage.Items.Clear();
                btnAdd.Enabled = false;
                return;
            }

            PageInfo[] pages = SearchTools.SearchSimilarPages(txtPageName.Text, lstNamespace.SelectedValue);

            lstAvailablePage.Items.Clear();

            foreach (PageInfo page in pages)
            {
                PageContent content = Content.GetPageContent(page, false);
                lstAvailablePage.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));
            }

            btnAdd.Enabled = pages.Length > 0;
        }