// Home Paage public IActionResult Index(string searchTerms, string targetURL, string numResults) { if (!string.IsNullOrEmpty(searchTerms)) { // Set the search filters GoogleFilter filters = new GoogleFilter(Convert.ToInt32(numResults)); // Object used to perform search queries and get parsed results GoogleSearch google = new GoogleSearch(filters); // Get results for query filtred by url List <WebResult> results = google.RunSearchQuery(searchTerms, targetURL); // A web exception was thrown if (results == null) { ViewData["WebError"] = "A web error has occured"; } // Pass data to view ViewData["Results"] = results; ViewData["ResultCount"] = results.Count; ViewData["TargetURL"] = targetURL; ViewData["NumResults"] = numResults; ViewData["Query"] = searchTerms; } return(View()); }
public void TestGoogleFilter() { // Given... GoogleFilter filter = new GoogleFilter(5); // When... filter.SetTimePeriod("Year"); // Then... Assert.Equal("y", filter.GetTimePeriod()); }
public void GoogleParserTest() { // given... GoogleFilter filter = new GoogleFilter(5); GoogleSearch google = new GoogleSearch(filter); GoogleResultsParser parser = new GoogleResultsParser(); // open file string currentpath = Directory.GetCurrentDirectory(); string testProjectPath = Path.GetFullPath(Path.Combine(currentpath, @"../../../")); string testFilePath = Path.Combine(testProjectPath, "GoogleResultsTestHtml.txt"); string testHtml = File.ReadAllText(testFilePath, Encoding.UTF8); // when... List <WebResult> results = parser.ParseHtmlToSearchResults(testHtml, "info"); // then... Assert.Equal(3, results.Count); Assert.Equal("https://www.infotrack.co.uk/", results[0].Url); Assert.Equal(1, results[0].Rank); Assert.Equal(3, results[2].Rank); Assert.Equal("InfoTrack", results[0].Title); Assert.Equal("Conveyancing Searches - InfoTrack | LEAP UK", results[1].Title); }