Exemplo n.º 1
0
        public async Task <SEORankingModel> SearchResultRankingsAsync(string searchTerm, string matchUri)
        {
            var start   = 0;
            var results = new List <SearchResult>();
            SearchResultsPage searchResultsPage = default;

            matchUri = RemoveProtocol(matchUri);

            while (results.Count < settings.CheckTopResults)
            {
                var    uri      = BuildUrl(searchTerm, start);
                string pageHtml = await this.scraper.GetPageSourceAsync(uri);

                searchResultsPage = parser.Parse(pageHtml);

                results.AddRange(searchResultsPage.SearchResults);
                start += 10;
            }

            var rankings = results.Select((r, i) => new { r.Uri, Ranking = i + 1 })
                           .Where(r => RemoveProtocol(r.Uri) == matchUri)
                           .Select(r => r.Ranking)
                           .ToArray();

            SEORankingModel response = new SEORankingModel
            {
                Rankings = string.Join(", ", rankings)
            };

            return(response);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index([FromQuery(Name = "term")] string term, [FromQuery(Name = "matchUri")] string matchUri)
        {
            var model = new SEORankingModel
            {
                Term     = term,
                MatchUri = matchUri
            };

            if (!string.IsNullOrEmpty(term))
            {
                model = await searchResultsAnalyzer.SearchResultRankingsAsync(term, matchUri);
            }
            return(View(model));
        }