private static void GetMusicReviews()
        {
            //Get a list of different content types with a count for each
            var op = new OpenPlatformSearch();
            var results = op.Search(new ContentSearchParameters { Count = 100, Filters = new List<string> {"/global/albumreview" } });
            var types = results.Results
                .Select(c => c.TaggedWith.Where(t => t.Type == "keyword"))
                .SelectMany(i => i)
                .Distinct(new TagComparer());
            foreach (var item in types)
            {
                Console.WriteLine(item.Name);
            }
            var typeCounts = results.Results
                .Where(c => c.TaggedWith.Any(t => t.Type == "keyword" && t.Name.Contains("music")))
                .GroupBy(c => (c.TaggedWith.First(t => t.Name.Contains("music")).Name))
                .Select(c => new { ContentType = c.Key, Count = c.Count() });

            foreach (var typeCount in typeCounts)
            {
                Console.WriteLine("Type: " + typeCount.ContentType + " Count: " + typeCount.Count);
            }

            var authorCounts = results.Results
                .GroupBy(c => (c.Byline))
                .Select(c => new { ContentType = c.Key, Count = c.Count() });

            foreach (var typeCount in authorCounts)
            {
                Console.WriteLine("Type: " + typeCount.ContentType + " Count: " + typeCount.Count);
            }
        }
        public void TestGetReviewType_with_real_data()
        {
            //http://content.guardianapis.com/stage/2010/nov/24/the-invisible-man-review
            //http://content.guardianapis.com/stage/2010/nov/24/hunt-for-the-scroobious-pip-review
            //http://content.guardianapis.com/tv-and-radio/2010/nov/24/arise-black-man-peter-tosh-review
            //http://content.guardianapis.com/tv-and-radio/2010/nov/23/how-roald-dahl-shaped-pop-review
            //http://content.guardianapis.com/technology/gamesblog/2010/nov/22/we-sing-robbie-williams-review
            //http://content.guardianapis.com/tv-and-radio/2010/nov/22/tv-review-any-human-heart
            //load some reviews from a text file using a fake
            var op = new OpenPlatformSearch(new ApiService("Reviews2.json"), "", "");
            var results = op.ContentSearch(new ContentSearchParameters());
            results.Results.Count().ShouldBe(50);

            var content = results.Results
                .Where(c => c.ApiUrl == "http://content.guardianapis.com/stage/2010/nov/24/the-invisible-man-review").First();
            content.GetReviewType().ShouldBe(ReviewTypes.Theatre);

            content = results.Results
                .Where(c => c.ApiUrl == "http://content.guardianapis.com/technology/gamesblog/2010/nov/22/we-sing-robbie-williams-review").First();
            content.GetReviewType().ShouldBe(ReviewTypes.Game);

            content = results.Results
                .Where(c => c.ApiUrl == "http://content.guardianapis.com/tv-and-radio/2010/nov/24/arise-black-man-peter-tosh-review").First();
            content.GetReviewType().ShouldBe(ReviewTypes.TvAndRadio);

            //var multiples = results.Results.Where(c => converter.GetReviewTypesFromTag(c).Count > 1);
            //foreach (var multiple in multiples)
            //{
            //    System.Diagnostics.Debug.WriteLine(multiple.ApiUrl);
            //}
            //var count = multiples.Count();
        }
 public void can_get_correct_number_of_reviews()
 {
     var op = new OpenPlatformSearch(new ApiService("ReviewsWithAllFields.json"), "", "");
     var rf = new ReviewFetcher(op);
     var reviews = rf.FetchReviews();
     reviews.Count().ShouldBe(50);
 }
 protected static void GetItem()
 {
     //Get an item by Id
     var op = new OpenPlatformSearch();
     var item = op.Item(353757375);
     Console.WriteLine("author name: " + item.Byline);
     if(item.Type == "article")
         Console.WriteLine(item.TypeSpecific.Body);
 }
        public void Can_insert_Content()
        {
            SessionManager.CreateSchema();
            var op = new OpenPlatformSearch(new ApiService("ReviewsWithAllFields.json"), "", "");

            var fetcher = new ReviewFetcher(op);
            var reviews = fetcher.FetchReviews();
            var repository = new QueryRepository<Review>();
            var nulls = reviews.Where(r => r.ReviewType == null).ToList();
            repository.SaveMany(reviews);
        }
        public void Can_get_and_insert_live_Content()
        {
            SessionManager.CreateSchema();
            var op = new OpenPlatformSearch();

            var fetcher = new ReviewFetcher(op);
            var reviews = fetcher.FetchReviews();
            var repository = new QueryRepository<Review>();
            var nulls = reviews.Where(r => r.ReviewType == null).ToList();
            repository.SaveMany(reviews);
        }
        public void Test_Item_Search()
        {
            var op = new OpenPlatformSearch(new ApiService("Json\\Article.json"));
            var item = op.Item("tv-and-radio/2010/apr/10/charlie-brooker-mad-men-screenburn");

            Assert.AreEqual("tv-and-radio/2010/apr/10/charlie-brooker-mad-men-screenburn", item.Id);
            //Assert.AreEqual("article", item.Type);
            Assert.AreEqual("Charlie Brooker", item.Fields.Byline);
            Assert.AreEqual(8, item.Tags.Count());
            Assert.AreEqual(2010, item.WebPublicationDate.Year);
        }
        public void Test_Tag_Search()
        {
            var op = new OpenPlatformSearch(new ApiService("Json\\Tags.json"));
            var item = op.Tags(new TagSearchParameters());

            Assert.IsNotNull(item.Results);
            Assert.AreEqual(10, item.Results.Count());
            var second = item.Results[1];
            Assert.AreEqual("Dick Vinegar", second.WebTitle);
            Assert.AreEqual("contributor", second.Type);
            Assert.AreEqual("profile/dick-vinegar", second.Id);
            Assert.AreEqual("http://content.guardianapis.com/profile/dick-vinegar", second.ApiUrl);
            Assert.AreEqual("http://www.guardian.co.uk/profile/dick-vinegar", second.WebUrl);
        }
        private static void GetDistinctItemTypes()
        {
            //Get a list of different content types with a count for each
            var op = new OpenPlatformSearch();
            var results = op.Search(new ContentSearchParameters {Count = 100});

            var typeCounts = results.Results
                .GroupBy(c => c.Type)
                .Select(c => new {ContentType = c.Key, Count = c.Count()});

            foreach(var typeCount in typeCounts)
            {
                Console.WriteLine("Type: " + typeCount.ContentType + " Count: " + typeCount.Count);
            }
        }
Esempio n. 10
0
 protected static void SimpleSearch()
 {
     //A simple content search
     var op = new OpenPlatformSearch();
     var results = op.Search(new ContentSearchParameters
     {
         Query = "Nina Nastasia",
         Count = 20,
     });
     Console.WriteLine("Number of results: " + results.Count);
     foreach (var item in results.Results)
     {
         Console.WriteLine(item.Headline);
     }
 }
 public static SearchResults GetMusicContentForLastNDays(double numberOfDays)
 {
     var op = new OpenPlatformSearch();
     var date = DateTime.Today.AddDays(-numberOfDays);
     var results = op.Search(new ContentSearchParameters
     {
         After = date,
         Count = 100, //there will be fewer results than this, we just want to bring them all back
         Filters = new List<string>
         {
             "/music"
         }
     });
     return results;
 }
        public void Test_Search()
        {
            var op = new OpenPlatformSearch(new ApiService("Json\\ContentSearch.json"));
            var results = op.ContentSearch(new ContentSearchParameters
            {
                Query = "Nina Nastasia",
                PageSize = 20
            });

            Assert.AreEqual(10, results.Results.Count());
            var article = results.Results[0];
            Assert.AreEqual(2004, article.WebPublicationDate.Year);

            var video = results.Results[7];
        }
Esempio n. 13
0
        protected static void SearchWithFilters()
        {
            //A content search with filters
            var op = new OpenPlatformSearch();
            var parameters = new ContentSearchParameters
                                 {
                                     Query = "prince",
                                     Count = 20,
                                     Filters = new List<string>{"music"}
                                 };

            var results = op.Search(parameters);

            Console.WriteLine("Number of results: " + results.Count);
            foreach (var item in results.Results)
            {
                Console.WriteLine(item.Headline);
            }
        }
 public ActionResult Results(ContentSearchParameters parameters)
 {
     OpenPlatformSearch op = new OpenPlatformSearch();
     var results = op.Search(parameters);
     return View(results);
 }
 public ReviewFetcher(OpenPlatformSearch contentApi)
 {
     _contentApi = contentApi;
 }
        public void Can_get_and_insert_live_Content()
        {
            var session = NHibernateSession.GetDefaultSessionFactory().OpenSession();
            new SchemaExport(_configuration).Create(false, true);
            //add the enumerations
            foreach (MusicTypes i in Enumeration.GetAll<MusicTypes>())
            {
                session.Save(i);
            }
            foreach (ReviewTypes i in Enumeration.GetAll<ReviewTypes>())
            {
                session.Save(i);
            }
            //add a user
            var u = new User {ClaimedIdentifier = "test", Email = "*****@*****.**"};
            u.ExcludedReviewTypes.Add(ReviewTypes.Game);
            session.SaveOrUpdate(u);

            //session.Flush();
            var op = new OpenPlatformSearch();

            var fetcher = new ReviewFetcher(op);
            var reviews = fetcher.FetchReviews();
            var repository = new QueryRepository<Review>();
            var nulls = reviews.Where(r => r.ReviewType == null).ToList();
            nulls.Count.ShouldBe(0);

            repository.SaveMany(reviews);
            repository.DbContext.CommitChanges();
        }
Esempio n. 17
0
        private static void GetMusicReviewsByDate()
        {
            //Get a list of authors with a count for each
            var op = new OpenPlatformSearch();
            var results = op.Search(new ContentSearchParameters
            {
                Count = 100,
                Filters = new List<string> { "/global/albumreview" }
            });

            var byDate = results.Results
                .GroupBy(c => c.PublicationDate)
                .Select(c => new { date = c.Key, Count = c.Count() });
            foreach (var item in byDate)
            {
                Console.WriteLine("Date: " + item.date + " Day: " + item.date.DayOfWeek + " Count: " + item.Count);
            }
        }