protected void Page_Load(object sender, EventArgs e)
        {
            InitLookUpDictionary();

            //Check we have a search term
            var orgSearchTerm = Request.QueryString["q"].Trim();
            searchTerm = orgSearchTerm.Replace(" OR ", " ").Replace(" or ", " ");
            if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length == 1)
            {
                phNotValid.Visible = true;
                phResults.Visible = false;
                return;
            }

            Searcher = ExamineManager.Instance.SearchProviderCollection["MultiIndexSearcher"];

            //Search Criteria for WIKI & Projects
            bool andSearch = false;
            var searchCriteria = Searcher.CreateSearchCriteria(BooleanOperation.Or);
            if (searchTerm.IndexOf("\"") == -1 && searchTerm.ToLower().IndexOf(" and ") > -1)
            {
                andSearch = true;
                searchTerm = searchTerm.Replace(" and ", " ").Replace(" AND ", " ");
            }

            /*var searchFilter = searchCriteria.Field("a","b").Or().GroupedOr
               .GroupedOr(new string[] { "nodeName", "bodyText", "description", "Title", "Body", "CommentsContent" }, searchTerm)
               .Compile();*/

            var searchQuery = searchTerm.BuildExamineString(10, "nodeName", andSearch);
            searchQuery += searchTerm.BuildExamineString(8, "bodyText", andSearch);
            searchQuery += searchTerm.BuildExamineString(9, "description", andSearch);
            searchQuery += searchTerm.BuildExamineString(10, "Title", andSearch);
            searchQuery += searchTerm.BuildExamineString(8, "Body", andSearch);
            searchQuery += searchTerm.BuildExamineString(7, "CommentsContent", andSearch).TrimEnd(' ');

            var searchFilter = searchCriteria.RawQuery(searchQuery);

            searchResults = Searcher.Search(searchFilter).OrderByDescending(x => x.Score);

            // set the searchterm back for the results view
            searchTerm = orgSearchTerm;

            //Get where to search (content)
            string searchWhere = Request.QueryString["content"];

            searchResults = FilterOnContentType(searchWhere, searchResults);

            BindResultsAndSetUpPaging(searchResults);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check we have a search term
            var orgSearchTerm = Request.QueryString["q"].Trim();
            searchTerm = orgSearchTerm.Replace(" OR ", " ").Replace(" or ", " ");
            if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length == 1)
            {
                phNotValid.Visible = true;
                phResults.Visible = false;
                return;
            }

            Searcher = ExamineManager.Instance.SearchProviderCollection["MultiIndexSearcher"];

            //Search Criteria for WIKI & Projects
            bool andSearch = false;
            var searchCriteria = Searcher.CreateSearchCriteria(BooleanOperation.Or);
            if (searchTerm.IndexOf("\"") == -1 && searchTerm.ToLower().IndexOf(" and ") > -1)
            {
                andSearch = true;
                searchTerm = searchTerm.Replace(" and ", " ").Replace(" AND ", " ");
            }

            /*var searchFilter = searchCriteria.Field("a","b").Or().GroupedOr
               .GroupedOr(new string[] { "nodeName", "bodyText", "description", "Title", "Body", "CommentsContent" }, searchTerm)
               .Compile();*/

            var searchQuery = searchTerm.BuildExamineString(10, "nodeName", andSearch);
            searchQuery += searchTerm.BuildExamineString(8, "bodyText", andSearch);
            searchQuery += searchTerm.BuildExamineString(9, "description", andSearch);
            searchQuery += searchTerm.BuildExamineString(10, "Title", andSearch);
            searchQuery += searchTerm.BuildExamineString(8, "Body", andSearch);
            searchQuery += searchTerm.BuildExamineString(7, "CommentsContent", andSearch).TrimEnd(' ');

            var searchFilter = searchCriteria.RawQuery(searchQuery);

            searchResults = Searcher.Search(searchFilter).OrderByDescending(x => x.Score);

            // set the searchterm back for the results view
            searchTerm = orgSearchTerm;

            //Get where to search (content)
            string searchWhere = Request.QueryString["content"];
            if (searchWhere.Contains("wiki") && !searchWhere.Contains("project") && !searchWhere.Contains("forum"))
            {
                //only wiki
                searchResults = from r in searchResults where r["__IndexType"] == "content" && r["nodeTypeAlias"] == "WikiPage" select r;
            }
            else if (!searchWhere.Contains("wiki") && searchWhere.Contains("project") && !searchWhere.Contains("forum"))
            {
                //only projects
                searchResults = from r in searchResults where r["__IndexType"] == "content" && (r["nodeTypeAlias"] == "Project" && r["projectLive"] == "1") select r;
            }
            else if (!searchWhere.Contains("wiki") && !searchWhere.Contains("project") && searchWhere.Contains("forum"))
            {
                //only forum
                searchResults = from r in searchResults where r["__IndexType"] == "documents" select r;
            }
            else if (searchWhere.Contains("wiki") && searchWhere.Contains("project") && !searchWhere.Contains("forum"))
            {
                //wiki and projects
                searchResults = from r in searchResults where r["__IndexType"] == "content" && (r["nodeTypeAlias"] == "WikiPage" || (r["nodeTypeAlias"] == "Project" && r["projectLive"] == "1")) select r;
            }
            else if (searchWhere.Contains("wiki") && !searchWhere.Contains("project") && searchWhere.Contains("forum"))
            {
                //wiki and forum
                searchResults = from r in searchResults where r["__IndexType"] == "documents" || r["nodeTypeAlias"] == "WikiPage" select r;
            }
            else if (!searchWhere.Contains("wiki") && searchWhere.Contains("project") && searchWhere.Contains("forum"))
            {
                //project and forum
                searchResults = from r in searchResults where r["__IndexType"] == "documents" || (r["nodeTypeAlias"] == "Project" && r["projectLive"] == "1") select r;
            }
            else
            {
                searchResults = from r in searchResults where r["__IndexType"] == "documents" || r["nodeTypeAlias"] == "WikiPage" || (r["nodeTypeAlias"] == "Project" && r["projectLive"] == "1") select r;
            }

            //Setup paging. If there isn't a page specified default to page 0
            int page = 0;
            int.TryParse(Request.QueryString["p"], out page);
            int ItemsPerPage = 20;

            //Bind repater to the list of results
            searchResultListing.DataSource = searchResults.Skip(page * ItemsPerPage).Take(ItemsPerPage);
            searchResultListing.DataBind();

            //Page numbering...
            int numberOfResults = searchResults.Count();
            int numberOfPages = (int)Math.Round((float)numberOfResults / (float)ItemsPerPage, 0);

            if (numberOfPages > 1)
            {
                //Lets generate the HTML string up for the pager....
                pager.Text = "<div><strong>Pages:</strong></div><ul class=\"deliPaging\">";

                for (int i = 0; i < numberOfPages; i++)
                {
                    pager.Text += "<li>";

                    if (page == i)
                        pager.Text += "<a href='?q=" + searchTerm + "&content=" + Request.QueryString["content"] + "&p=" + i + "' class='selected'>";
                    else
                        pager.Text += "<a href='?q=" + searchTerm + "&content=" + Request.QueryString["content"] + "&p=" + i + "'>";

                    pager.Text += i + 1;
                    pager.Text += "</a>";
                    pager.Text += "</li>";
                }

                pager.Text += "</ul>";
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a base search criteria for getting posts.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        protected ISearchCriteria GetPostBaseCriteria(IPublishedContent node, BaseSearchProvider searcher)
        {
            var landing = DataService.Instance.GetLanding(node);

            var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);
            criteria.Field("nodeTypeAlias", "uBlogsyPost")
                    .And()
                    .Field(uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchablePath, landing.Id.ToString())
                    .Not()
                    .Field("umbracoNaviHide", "1");

            return criteria;
        }