Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string searchType = Strings.Clean(Request.Params["cbsubmit"]);
            int    startMonth = Strings.ToInt(Strings.Clean(Request.Params["startMonth"]));
            int    startYear  = Strings.ToInt(Strings.Clean(Request.Params["startYear"]));
            int    endMonth   = Strings.ToInt(Strings.Clean(Request.Params["endMonth"]));
            int    endYear    = Strings.ToInt(Strings.Clean(Request.Params["endYear"]));

            keyword = Strings.Clean(Request.Params["cbkeyword"]);
            int  currentPage  = Strings.ToInt(Strings.Clean(Request.Params["page"]));
            bool bSearchRange = false;

            if (Page.Request.HttpMethod == "POST")
            {
                bSearchRange = (Request.Params["searchRangeButton"] != null);
            }
            else
            {
                bSearchRange = (searchType != null && string.Compare(searchType, "range", true) == 0);
            }



            firstRecord = 0;
            lastRecord  = 0;
            totalItems  = 0;

            if (currentPage < 0)
            {
                currentPage = 1;
            }
            int pageSize = 10;

            if (keyword == null)
            {
                resultsHtml = "<br><br>Please enter a search phrase.<br><br><br>";
            }
            else
            {
                firstRecord = (currentPage - 1) * pageSize + 1;
                recordIndex = firstRecord;

                //set up the search collection
                //determine what text needs to be removed from the title e.g. - National Cancer Institute
                SiteWideSearchConfig searchConfig = ModuleObjectFactory <SiteWideSearchConfig> .GetModuleObject(SnippetInfo.Data);

                if (searchConfig != null)
                {
                    SearchCollection = searchConfig.SearchCollection;
                    ResultTitleText  = searchConfig.ResultTitleText;
                }

                ISiteWideSearchResultCollection results;
                try
                {
                    results = NCI.Search.SiteWideSearch.GetSearchResults(SearchCollection, Keyword, pageSize,
                                                                         (currentPage - 1) * pageSize);

                    if (results != null && results.ResultCount > 0)
                    {
                        lastRecord = firstRecord + (int)results.ResultCount - 1;
                        totalItems = (int)results.ResultCount;

                        ResultRepeater.DataSource = results;
                        ResultRepeater.DataBind();

                        //pager code
                        string urlFormat;
                        string pagerUrl;
                        if (bSearchRange)
                        {
                            urlFormat = PrettyUrl + "?cbsubmit=range&cbkeyword={0}&startMonth={1}&startYear={2}&endMonth={3}&endYear={4}";
                            pagerUrl  = String.Format(urlFormat, Server.UrlEncode(keyword), startMonth.ToString(), startYear.ToString(), endMonth.ToString(), endYear.ToString());
                        }
                        else
                        {
                            urlFormat = PrettyUrl + "?cbkeyword={0}";
                            pagerUrl  = String.Format(urlFormat, Server.UrlEncode(keyword));
                        }

                        ResultPager objPager = new ResultPager(pagerUrl, currentPage, pageSize, 2, totalItems);
                        pager = objPager.RenderPager();
                    }
                    else
                    {
                        firstRecord = 0;
                    }
                }
                catch (Exception ex)
                {
                    //capture exactly which keyword caused the error
                    log.ErrorFormat("{0} - Search with the following keyword returned an error: {1}", ex, PrettyUrl, Keyword);
                    this.RaiseErrorPage();
                }


                //eSearch.FillSearchResults(eSearchResults);
            }

            this.PageInstruction.AddFieldFilter("channelName", (fieldName, data) =>
            {
                data.Value = "Newsletter";
            });
        }
Пример #2
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //Get Settings
            if (Request.RequestType == "POST")
            {
            }
            else
            {
                //The method was a GET, therfore we must be paging.
                _currentPage    = Strings.ToInt(Request.Params["PageNum"], 1);
                _recordsPerPage = Strings.ToInt(Request.Params["RecordsPerPage"], 10);
                _offSet         = Strings.ToInt(Request.Params["OffSet"], 0);
            }

            if (PerformSearch)
            {
                if (Keyword != null)
                {
                    //Store keyword in viewstate (This does not check if it is not there already)
                    if (ViewState[swKeyword] == null)
                    {
                        ViewState.Add(swKeyword, Keyword);
                    }
                    else
                    {
                        ViewState[swKeyword] = Keyword;
                    }

                    //set up the search collection
                    //determine what text needs to be removed from the title e.g. - National Cancer Institute
                    SiteWideSearchConfig searchConfig = ModuleObjectFactory <SiteWideSearchConfig> .GetModuleObject(SnippetInfo.Data);

                    if (searchConfig != null)
                    {
                        SearchCollection = searchConfig.SearchCollection;
                        ResultTitleText  = searchConfig.ResultTitleText;
                    }

                    try
                    {
                        long dimFilter = Strings.ToLong(ConfigurationManager.AppSettings["EndecaSWSearchDimFilter"], 0);

                        ISiteWideSearchResultCollection results = NCI.Search.SiteWideSearch.GetSearchResults(SearchCollection, Keyword, _recordsPerPage,
                                                                                                             (_currentPage - 1) * _recordsPerPage);

                        rptSearchResults.DataSource = results;
                        rptSearchResults.DataBind();

                        if (results.ResultCount == 0)
                        {
                            ResultsText = "No results found";
                            rptSearchResults.Visible = false;
                        }
                        else
                        {
                            int startRecord = 0;
                            int endRecord   = 0;
                            _resultsFound = true;
                            SimplePager.GetFirstItemLastItem(_currentPage, _recordsPerPage, (int)results.ResultCount, out startRecord, out endRecord);

                            //phNoResultsLabel.Visible = false;
                            rptSearchResults.Visible = true;
                            string resultsCount = String.Format("{0}-{1} of {2}", startRecord.ToString(), endRecord.ToString(), results.ResultCount.ToString());
                            ResultsText = "Results " + resultsCount;
                        }

                        spPager.RecordCount    = (int)results.ResultCount;
                        spPager.RecordsPerPage = _recordsPerPage;
                        spPager.CurrentPage    = _currentPage;
                        spPager.BaseUrl        = PrettyUrl + "?swKeywordQuery=" + Keyword;
                    }
                    catch (Exception ex)
                    {
                        //capture exactly which keyword caused the error
                        log.ErrorFormat("Search with the following keyword returned an error: {0}", ex, Keyword);
                    }
                }
                else
                {
                    ResultsText = "No results found";
                    rptSearchResults.Visible = false;
                }
            }
            else
            {
                ResultsText = String.Empty;
            }
        }
Пример #3
0
        /// <summary>
        /// Event method sets content version and template and user control properties<br /><br />
        /// [1] Input form parameters:<br />
        /// keyword {string: search string},<br />
        /// first {integer: ordinal index of first result},<br />
        /// resultSearch {string: search within results search string},<br />
        /// chkCategories {comma-delimited set of strings: specific virtual paths to search},<br />
        /// selectedPage {integer: current result page number}<br />
        /// [2] Builds Verity and BestBet query language and Verity query xml document<br />
        /// [3] Parses Verity results and errors<br />
        /// [4] Builds Verity and BestBet result HTML<br />
        /// [5] Builds paging control for results browsing<br />
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //Setup the title, header, and left nav
            SetupCancerGovPageStuff();

            SetLabels();

            //Hide the error message
            phError.Visible = false;

            //set up the search collection (CancerGovEnglish or CancerGovSpanish)
            //determine what text needs to be removed from the title e.g. - National Cancer Institute
            SiteWideSearchConfig searchConfig = ModuleObjectFactory <SiteWideSearchConfig> .GetModuleObject(SnippetInfo.Data);

            if (searchConfig != null)
            {
                SearchCollection = searchConfig.SearchCollection;
            }


            if (Page.Request.RequestType == "POST")
            {
                if (!IsPostBack)
                {
                    /*********************************************/
                    /*        Search using header search box     */
                    /*********************************************/

                    Keyword = Request.Params["swKeyword"];

                    if (Keyword == string.Empty)
                    {
                        ShowErrorMessage();
                    }
                    else
                    {
                        LoadResults();

                        //Log User Input for initial search.
                        LogUserInput("Keyword:" + Keyword);
                    }
                }
                else
                {
                    //This is a postback from a user changing the items per page or
                    //searching within results.  There is one problem though.
                    //By default,
                    if (Strings.Clean(Request.Params["__EVENTTARGET"]) == null &&
                        Strings.Clean(Request.Params["__EVENTARGUMENT"]) == null &&
                        Strings.Clean(Request.Params[btnTextChangePageUnit.UniqueID]) == null &&
                        Strings.Clean(Request.Params[btnSWRTxtSearch.UniqueID]) == null)
                    {
                        //THIS IS FOR IE with no JS.  Oddly in most ways it is more broken than firefox, but
                        //is so broken that we can easily tell that the user hit enter on the only
                        //text box.
                        //Basically if all the buttons that can be clicked are null, and there
                        //is no event target or argument, then this is IE with Javascript turned
                        //off and the user clicked enter on the text box.  Also, image buttons do
                        //not come back ID, but ID.x and ID.y. (Hopefully screen readers send those
                        //things too.
                        //
                        //We need to handle this stuff after all the other postback events happen.
                        //so lets just set a variable for now.
                        _isIENoJSAndHitEnderInTheSearchBox = true;
                    }
                }
            }
            else
            {
                /*********************************************/
                /*    Either Paging or a DYM Click           */
                /*********************************************/

                //No Matter if this is a DYM or a Paging, swKeyword is the keyword. (There may be an old one, but that is for later)
                Keyword = Request.Params["swKeyword"];

                if (Keyword == string.Empty)
                {
                    ShowErrorMessage();
                }
                else
                {
                    //These things only apply to paging

                    //Get Items per page.
                    ItemsPerPage = Strings.ToInt(Request.Params["pageunit"], 10);

                    //Get the current Page
                    CurrentPage = Strings.ToInt(Request.Params["page"], 1);

                    //"De-serialize" old keywords.
                    if (!string.IsNullOrEmpty(Request.Params["old_keywords"]))
                    {
                        string[] oldKeys = Request.Params["old_keywords"].Split(new char[] { '|' });
                        OldKeywords.AddRange(oldKeys);
                    }

                    LoadResults();
                }
            }

            // build the OnClineClick value for results search
            var siteResultSearchSubmitParameter = "";

            if (PageDisplayInformation.Language == DisplayLanguage.Spanish)
            {
                siteResultSearchSubmitParameter = "true";
            }
            // removed search validation for now
            var siteResultSearchSubmitCall = ""; //"return siteResultSearchSubmit(" + siteResultSearchSubmitParameter + ")";

            // Web Analytics *************************************************
            if (WebAnalyticsOptions.IsEnabled)
            {
                siteResultSearchSubmitCall += "return NCIAnalytics.SiteWideSearchResultsSearch(this,'" + txtSWRKeyword.ClientID + "','" + rblSWRSearchType.UniqueID + "')";
            }
            // End Web Analytics *********************************************
            if (!String.IsNullOrEmpty(siteResultSearchSubmitCall))
            {
                siteResultSearchSubmitCall   += ";";
                btnSWRTxtSearch.OnClientClick = siteResultSearchSubmitCall;
            }
        }