/// <summary> /// ALL processing happens here, since we are not using ASP.NET controls or events. /// Page_Load will: /// * check the Cache for a catalog to use /// * if not, check the filesystem for a serialized cache /// * and if STILL not, Server.Transfer to the Spider to build a new cache /// * check the QueryString for search arguments (and if so, do a search) /// * otherwise just show the HTML of this page - a blank search form /// </summary> public void Page_Load() { // prevent Searcharoo from indexing itself (ie. it's own results page) if ((Request.UserAgent != null) && (Request.UserAgent.ToLower().IndexOf("searcharoo") > 0)) { Response.Clear(); Response.End(); return; } bool getCatalog = false; try { // see if there is a catalog object in the cache _Catalog = (Catalog)Application["Searcharoo_Catalog"]; // if so, get the _WordCount _WordCount = _Catalog.Length; _Cache = (Searcharoo.Common.Cache)Application["Searcharoo_Cache"]; } catch (Exception ex) { // otherwise, we'll need to build the catalog log.Warn("Catalog object unavailable : building a new one!"); _Catalog = null; // in case _Cache = null; } ucSearchPanelHeader.WordCount = _WordCount; //ucSearchPanelFooter.WordCount = _WordCount; if (_Catalog == null) { getCatalog = true; } else if (_Catalog.Length == 0) { getCatalog = true; } if (getCatalog) { // Create the thread object, passing in the Alpha.Beta method // via a ThreadStart delegate. This does not start the thread. SearchCatalogInit sci = new SearchCatalogInit(); Thread t = new Thread(() => sci.GetCatalog(this)); t.Start(); if ((string)Application["CatalogLoad"] == "") { // Still no Catalog, so we have to start building a new one if (_Catalog == null) { _Catalog = (Catalog)Application["Searcharoo_Catalog"]; _Cache = (Searcharoo.Common.Cache)Application["Searcharoo_Cache"]; } } } if (this.SearchQuery == "") { ucSearchPanelHeader.IsSearchResultsPage = false; } else { //refactored into class - catalog can be build via a console application as well as the SearchSpider.aspx page Searcharoo.Engine.Search se = new Searcharoo.Engine.Search(); SortedList output = this.GetSearchResults(se); // se.GetResults(this.SearchQuery, _Catalog); _NumberOfMatches = output.Count.ToString(); if (output.Count > 0) { _PagedResults.DataSource = output.GetValueList(); _PagedResults.AllowPaging = true; _PagedResults.PageSize = MaxResultsPerPage; //;Preferences.ResultsPerPage; //10; _PagedResults.CurrentPageIndex = Request.QueryString["page"] == null ? 0 : Convert.ToInt32(Request.QueryString["page"]) - 1; _Matches = se.SearchQueryMatchHtml; _DisplayTime = se.DisplayTime; _Geocoded = se.GeocodedMatches; SearchResults.DataSource = _PagedResults; SearchResults.DataBind(); } else { lblNoSearchResults.Visible = true; } // Set the display info in the top & bottom user controls ucSearchPanelHeader.Word = this.SearchQuery; ucSearchPanelHeader.IsSearchResultsPage = true; } }