public void Serach() { GoogleSiteSearch search = new GoogleSiteSearch("UNEP"); List <GoogleSiteSearchResult> results = search.Search("2", "15"); GoogleSiteSearch search2 = new GoogleSiteSearch("UNEP", "www.latincarbon.com"); List <GoogleSiteSearchResult> results2 = search2.Search("1", "20"); XPathNodeIterator iterator = GoogleSiteSearchXsltExtension.Search("UNEP", 10, 1, "www.latincarbon.com"); }
protected void Page_Load(object sender, EventArgs e) { var skinnable = Master as BaseMasterPage; if (skinnable != null) { skinnable.Skin = new CustomerFocusSkin(ViewSelector.CurrentViewIs(MasterPageFile)); } // Use standard parameter instead of the old tQ if (String.IsNullOrEmpty(Request.QueryString["q"]) && !String.IsNullOrEmpty(Request.QueryString["tq"])) { var query = HttpUtility.ParseQueryString(Request.QueryString.ToString()); query.Remove("tq"); query.Add("q", Request.QueryString["tq"]); var revisedUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + Request.Url.AbsolutePath + "?" + query); new HttpStatus().MovedPermanently(revisedUrl); } // If there's a search query if (!String.IsNullOrEmpty(Request.QueryString["q"])) { // Redisplay search term if (!String.IsNullOrEmpty(Request.QueryString["refine"])) { this.Title = "Search results for '" + HttpUtility.HtmlEncode(Request.QueryString["refine"]) + "' within '" + HttpUtility.HtmlEncode(Request.QueryString["q"]) + "'"; } else { this.Title = "Search results for '" + HttpUtility.HtmlEncode(Request.QueryString["q"]) + "'"; } this.heading.InnerHtml = this.Title; this.catalogueSearch.InnerHtml = string.Format("<a href=\"https://e-library.eastsussex.gov.uk/cgi-bin/spydus.exe/ENQ/OPAC/BIBENQ?ENTRY_NAME=BS&ENTRY={0}&ENTRY_TYPE=K&NRECS=20&SORTS=HBT.SOVR&SEARCH_FORM=%2Fcgi-bin%2Fspydus.exe%2FMSGTRN%2FOPAC%2FBSEARCH&CF=GEN&ISGLB=0\"> Search the library catalogue for '{1}' </a>", HttpUtility.HtmlEncode(Request.QueryString["q"]), HttpUtility.HtmlEncode(Request.QueryString["q"])); // Search Google with standard options var service = new GoogleSiteSearch(ConfigurationManager.AppSettings["GoogleSearchEngineId"]); var cacheHours = new TimeSpan(Int32.Parse(ConfigurationManager.AppSettings["CacheHours"], CultureInfo.CurrentCulture), 0, 0); service.CacheStrategy = new FileCacheStrategy(Server.MapPath(ConfigurationManager.AppSettings["CacheFilePath"]), cacheHours); var query = new GoogleQuery(Request.QueryString["q"]); if (!String.IsNullOrEmpty(Request.QueryString["refine"])) { query.QueryWithinResultsTerms = Request.QueryString["refine"]; } query.PageSize = this.paging.PageSize; query.Page = this.paging.CurrentPage; try { var response = service.Search(query); // Display results this.paging.TotalResults = response.TotalResults; this.noResults.Visible = (this.paging.TotalResults == 0 && response.ResultsAvailable); this.resultsUnavailable.Visible = (this.paging.TotalResults == 0 && !response.ResultsAvailable); if (this.noResults.Visible == false) { this.searchLibrary.InnerHtml = string.Format("<a href=\"https://e-library.eastsussex.gov.uk/cgi-bin/spydus.exe/ENQ/OPAC/BIBENQ?ENTRY_NAME=BS&ENTRY={0}&ENTRY_TYPE=K&NRECS=20&SORTS=HBT.SOVR&SEARCH_FORM=%2Fcgi-bin%2Fspydus.exe%2FMSGTRN%2FOPAC%2FBSEARCH&CF=GEN&ISGLB=0\"> Search the library catalogue for '{1}' </a>", HttpUtility.HtmlEncode(Request.QueryString["q"]), HttpUtility.HtmlEncode(Request.QueryString["q"])); } var searchResults = response.Results(); this.results.DataSource = searchResults; this.results.DataBind(); // Display spelling suggestions if (response.SpellingSuggestions().Count > 0) { this.spelling.Visible = true; foreach (string suggestion in response.SpellingSuggestions()) { if (this.suggestions.Controls.Count > 0) { this.suggestions.Controls.Add(new LiteralControl(" or ")); } using (var spellingLink = new HtmlAnchor()) { spellingLink.InnerText = suggestion; spellingLink.HRef = Request.Url.LocalPath + "?q=" + HttpUtility.UrlEncode(suggestion); this.suggestions.Controls.Add(spellingLink); } } } } catch (XmlException ex) { // This catches where Google has a 500 error and sends back malformed XML, <GSP VER="3.2"> <ERROR>500</ERROR>. // Exception is "Unexpected end of file has occurred. The following elements are not closed: GSP. Line 3, position 19." this.noResults.Visible = true; new HttpStatus().BadGateway(); ex.ToExceptionless().Submit(); } } else { this.noResults.Visible = true; new HttpStatus().BadRequest(); } #if (!DEBUG) new HttpCacheHeaders().CacheUntil(Response.Cache, DateTime.Now.AddDays(1)); #endif }