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; } }
protected void Page_Load(object sender, EventArgs e) { // Dictionary query parameters string expandParam = Strings.Clean(Request.QueryString["expand"], "A"); //string languageParam = Strings.Clean(Request.QueryString["language"]); string languageParam = ""; //disable language selection by query parameter SearchString = Strings.Clean(Request.QueryString["search"]); //Create a safe search string to be passed to the URL string _safeSearchString = System.Web.HttpContext.Current.Server.UrlEncode(SearchString); _term = Strings.Clean(Request.QueryString["term"]); _version = Strings.Clean(Request.QueryString["version"]); if (!String.IsNullOrEmpty(SearchString)) { SearchString = SearchString.Replace("[", "[[]"); } // Pager query parameter variables _currentPage = Strings.ToInt(Request.Params["PageNum"], 1); _recordsPerPage = Strings.ToInt(Request.Params["RecordsPerPage"], 10); _offSet = Strings.ToInt(Request.Params["OffSet"], 0); //Determine Language - set language related values string pageTitle; string buttonText; string language; string reDirect; MobileTermDictionary.DetermineLanguage(languageParam, out language, out pageTitle, out buttonText, out reDirect); _language = language; _dictionaryURL = PageAssemblyContext.Current.PageAssemblyInstruction.GetUrl("CurrentUrl").ToString(); litPageUrl.Text = _dictionaryURL; litSearchBlock.Text = MobileTermDictionary.SearchBlock(_dictionaryURL, SearchString, language, pageTitle, buttonText, true); // Setup Pager variables int pager_StartRecord = 0; int pager_EndRecord = 0; int pager_MaxRows = 0; int pager_RowsPerPage = 10; TermDictionaryCollection dataCollection = null; if (!String.IsNullOrEmpty(SearchString)) // SearchString provided, do a term search { PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter(PageAssemblyInstructionUrls.AltLanguage, (name, url) => { url.QueryParameters.Add("search", _safeSearchString); }); PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter("CurrentUrl", (name, url) => { url.QueryParameters.Add("search", _safeSearchString); }); dataCollection = TermDictionaryManager.GetTermDictionaryList(language, SearchString, false, pager_RowsPerPage, _currentPage, ref pager_MaxRows); } else if (!String.IsNullOrEmpty(Term)) { DisplayLanguage dl; if (Language.ToLower().Trim() == "spanish") { dl = DisplayLanguage.Spanish; } else { dl = DisplayLanguage.English; } TermDictionaryDataItem di = TermDictionaryManager.GetDefinitionByTermName(dl, Term, Version, 2); string itemDefinitionUrl = DictionaryURL + "?cdrid=" + di.GlossaryTermID; Page.Response.Redirect(itemDefinitionUrl); } else if (!String.IsNullOrEmpty(expandParam)) // A-Z expand provided - do an A-Z search { _showDefinition = false; _expand = true; if (expandParam.Length > 0) { _expandText = expandParam.Substring(0, 1); if (_expandText == "#") { _expandText = "[0-9]"; } } else { _expandText = ""; } PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter(PageAssemblyInstructionUrls.AltLanguage, (name, url) => { url.QueryParameters.Add("expand", _expandText); }); PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter("CurrentUrl", (name, url) => { url.QueryParameters.Add("expand", _expandText); }); dataCollection = TermDictionaryManager.GetTermDictionaryList(language, _expandText.Trim().ToUpper(), false, pager_RowsPerPage, _currentPage, ref pager_MaxRows); } if (dataCollection != null) { if (dataCollection.Count == 1 && !Expand) //if there is only 1 record - go directly to definition view { //string itemDefinitionUrl = DictionaryURL + "?cdrid=" + dataCollection[0].GlossaryTermID + "&language=" + Language; string itemDefinitionUrl = DictionaryURL + "?cdrid=" + dataCollection[0].GlossaryTermID; Page.Response.Redirect(itemDefinitionUrl); } else // bind results { resultListView.DataSource = dataCollection; resultListView.DataBind(); } SimplePager.GetFirstItemLastItem(_currentPage, pager_RowsPerPage, pager_MaxRows, out pager_StartRecord, out pager_EndRecord); spPager.RecordCount = pager_MaxRows; spPager.RecordsPerPage = pager_RowsPerPage; spPager.CurrentPage = _currentPage; if (Expand) { spPager.BaseUrl = DictionaryURL + "?expand=" + _expandText; } else { spPager.BaseUrl = DictionaryURL + "?search=" + _safeSearchString; } if (IsSpanish) { spPager.PagerStyleSettings.NextPageText = "Siguiente >"; spPager.PagerStyleSettings.PrevPageText = "< Anterior"; } } }