/// <summary> /// Method that invokes the search engine to get resuts /// </summary> SortedList GetSearchResults(SearchEngine se) { if (!string.IsNullOrEmpty(Request.QueryString["semantics"]) && (Request.QueryString["semantics"].Equals("true", StringComparison.InvariantCultureIgnoreCase))) { SInfo = new EnableSemantics(); string newss = SInfo.GetSemanticSearchString(Request.QueryString[Preferences.QuerystringParameterName].ToString().Trim(' ')); SortedList res = new SortedList(); SortedList temp; IList tem2,tem1; int val; int i=1; foreach(string syn in newss.Split(" ".ToCharArray() , StringSplitOptions.RemoveEmptyEntries)) { temp = se.GetResults(syn, _Catalog); tem1 = temp.GetKeyList(); tem2 = temp.GetValueList(); for(int j=0;j<temp.Count;j++) { val = (int)tem1[j]; val*=i; res.Add(val,tem2[j]); } i++; if(i>5) break; } return res; } else { SortedList res = se.GetResults(this.SearchQuery, _Catalog); return res; } }
protected void Page_Load() { bool getCatalog = false; try { // see if there is a catalog object in the cache _Catalog = (Catalog)Cache[Preferences.CatalogCacheKey]; _WordCount = _Catalog.Length; // if so, get the _WordCount } catch (Exception ex) { // If not, we'll need to load_from_file or build the catalog again. Logger.PerformanceLog(this, "Catalog object unavailable : Loadind from file!" + ex.ToString()); _Catalog = null; // in case } if (null == _Catalog) getCatalog = true; else if (_Catalog.Length == 0) getCatalog = true; if (getCatalog) { // No catalog 'in memory', so let's look for one // First, for a serialized version on disk _Catalog = Catalog.Load(); // returns null if not found // Still no Catalog, so we have to start building a new one if (null == _Catalog) { Logger.PerformanceLog(this, "Catalog object unavailable & serialized file missing : Building new Catalog!"); Response.Redirect("Crawling.aspx", true); } else { // Yep, there was a serialized catalog file // Don't forget to add to cache for next time (the Spider does this too) Cache[Preferences.CatalogCacheKey] = _Catalog; _WordCount = _Catalog.Length; // if so, get the _WordCount Logger.PerformanceLog(this, "Deserialized catalog and put in Cache"); } } ucSearchPanelHeader.WordCount = _WordCount; ucSearchPanelFooter.WordCount = _WordCount; if (this.SearchQuery == "") { ucSearchPanelFooter.Visible = false; ucSearchPanelFooter.IsFooter = true; ucSearchPanelHeader.IsSearchResultsPage = false; } else { SearchEngine se = new SearchEngine(); SortedList output = GetSearchResults(se); // which'll do 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; SearchResults.DataSource = _PagedResults; SearchResults.DataBind(); } else { lblNoSearchResults.Visible = true; } // Set the display info in the top & bottom user controls ucSearchPanelHeader.Word = ucSearchPanelFooter.Word = SearchQuery; ucSearchPanelFooter.Visible = true; ucSearchPanelFooter.IsFooter = true; ucSearchPanelHeader.IsSearchResultsPage = true; } if (!string.IsNullOrEmpty(Request.QueryString["semantics"]) && (Request.QueryString["semantics"].Equals("true",StringComparison.InvariantCultureIgnoreCase))) { SemanticsPanel.Visible = true; SInformation.Text = SInfo.SemanticsHtml; } }