public static SearchResults FromYahooBoss(Yahoo.Boss.BossWebSearchResponse bossResults, string query)
        {
            var results = new SearchResults(
                query,
                bossResults.Count,
                bossResults.TotalResults,
                bossResults.Start
                );

            var batchOrdinal = 0;
            var queryOrdinal = results.QueryStart;

            foreach (var bossResult in bossResults.Results)
            {
                var result = new SearchResult
                {
                    BatchOrdinal = batchOrdinal++,
                    QueryOrdinal = queryOrdinal++,
                    Url          = bossResult.Url,
                    HtmlUrl      = bossResult.DisplayURl,
                    // example:
                    // http://74.6.116.71/search/srpcache?ei=UTF-8&p=c%23+strip+html&vm=r&fr=crmas&u=http://cc.bingj.com/cache.aspx?q=c%23+strip+html&d=4714388897793329&w=iYNpm0Wkcl9f2yCFkMI5wRa72IFiWm_0&icp=1&.intl=us&sig=DHDDZxF3Q1kJw4JCRf2m4w--
                    // The sig parameter seems to be a checksum of the URL.  Perhaps to prevent manufacturing the URL?  I don't know the checksum algorithm yet.
                    CacheUrl    = string.Empty, // Todo: set CacheUrl.  It is mostly the same as Bing.  See above.
                    Title       = HtmlRemoval.StripTags(bossResult.Title),
                    HtmlTitle   = bossResult.Title,
                    Snippet     = HtmlRemoval.StripTags(bossResult.Abstract),
                    HtmlSnippet = bossResult.Abstract
                };

                results.Add(result);
            }

            return(results);
        }
Example #2
0
        private static BossWebSearchResponse ParseResponse(WebResponse response)
        {
            using (var responseStream = new StreamReader(response.GetResponseStream()))
            {
                var root = JObject.Parse(responseStream.ReadToEnd());

                var bossResponse = root["bossresponse"];
                var web          = bossResponse["web"];

                var results = new BossWebSearchResponse
                {
                    StatusCode   = int.Parse((string)bossResponse["responsecode"]),
                    Start        = int.Parse((string)web["start"]),
                    Count        = int.Parse((string)web["count"]),
                    TotalResults = int.Parse((string)web["totalresults"]),
                    Results      = new List <BossWebSearchResult>()
                };

                var resultsArray = (JArray)web["results"];
                if (resultsArray != null)
                {
                    foreach (var item in resultsArray)
                    {
                        var result = new BossWebSearchResult
                        {
                            ClickUrl   = (string)item["clickurl"],
                            Url        = (string)item["url"],
                            DisplayURl = (string)item["dispurl"],
                            Title      = (string)item["title"],
                            Abstract   = (string)item["abstract"]
                        };

                        DateTime.TryParse((string)item["date"], out result.Date);
                        results.Results.Add(result);
                    }
                }

                return(results);
            }
        }