// [rgn] Public Methods (1) /// <summary> /// Binds the data. /// </summary> /// <param name="hostId">The host id.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> public void DataBind(int hostId, int?year, int?month, int?day) { //don't do data bind if year is null //just show listing if (year == null) { return; } this.Month = month; this.Year = year; this.Day = day; _mostKickedStories = ZeitgeistCache.GetMostPopularStories(hostId, this.NumberOfItems, this.Year.Value, this.Month, this.Day); _mostCommentedOnStories = ZeitgeistCache.GetMostCommentedOnStories(hostId, this.NumberOfItems, this.Year.Value, this.Month, this.Day); _mostUsedTags = ZeitgeistCache.GetMostUsedTags(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPopularDomains = ZeitgeistCache.GetMostPopularDomains(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPublishedDomains = ZeitgeistCache.GetMostPublishedDomains(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPublishedUsers = ZeitgeistCache.GetMostPublishedUsers(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _storiesSubmittedCount = ZeitgeistCache.GetNumberOfStoriesSubmitted(hostId, this.Year.Value, this.Month, this.Day); _storiesPublishedCount = ZeitgeistCache.GetNumberOfStoriesPublished(hostId, this.Year.Value, this.Month, this.Day); _kicksCount = ZeitgeistCache.GetNumberOfKicks(hostId, this.Year.Value, this.Month, this.Day); _commentsCount = ZeitgeistCache.GetNumberOfComments(hostId, this.Year.Value, this.Month, this.Day); _userRegistrationCount = ZeitgeistCache.GetNumberOfUserRegistrations(hostId, this.Year.Value, this.Month, this.Day); }
public StoryCollection FetchAll() { StoryCollection coll = new StoryCollection(); Query qry = new Query(Story.Schema); coll.LoadAndCloseReader(qry.ExecuteReader()); return coll; }
public async Task <StoryCollection> GetBestStoriesAsync() { StoryCollection colStory = new StoryCollection(); Uri uri = new Uri(HNBaseUrl + "/beststories.json"); RequestResult requestResult = await HttpHelper.SendRequestAsync(uri); if (requestResult.IsSuccess) { List <int> lstBestStoryIds = null; JArray rootObject = (JArray)JsonConvert.DeserializeObject(requestResult.Content); lstBestStoryIds = rootObject.ToObject <List <int> >(); foreach (int storyId in lstBestStoryIds) { Story story = await GetStoryAsync(storyId); if (story != null) { colStory.Add(story); } } } return(colStory); }
public async Task <ActionResult> Index(int?page) { if (page == null) { page = 1; } //string hnBaseUrl = ConfigurationManager.AppSettings["HNBaseUrl"]; //int pageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"].ToString()); _hackerNewsService.SetHNBaseUrl(HnBaseUrl); StoryRepo storyRepo = new StoryRepo(_hackerNewsService, HnBaseUrl); int[] storyIds = await storyRepo.GetBestStoryIds(); ViewBag.NumOfPages = Math.Ceiling((double)storyIds.Length / PageSize); ViewBag.CurrentPageNumber = page; int[] currentStoryIds = storyIds .Skip((page.Value - 1) * PageSize) .Take(PageSize) .ToArray(); StoryCollection colStory = await storyRepo.GetBestStories(currentStoryIds); return(View(colStory)); }
public async Task <StoryCollection> GetBestStories(int[] storyIds) { StoryCollection colStory = null; colStory = await _hackerNewsService.GetBestStoriesAsync(storyIds); return(colStory); }
public void AddStoryTest() { StoryCollection storyColl = new StoryCollection(); storyColl.Add(testModel1); storyColl.Add(testModel2); Assert.IsTrue(storyColl.Stories.Count == 2); }
public void NotExistTest() { StoryCollection storyColl = new StoryCollection(); storyColl.Add(testModel1); storyColl.Add(testModel2); Assert.IsFalse(storyColl.Exists(testModel3.id)); }
public void DoesExistTest() { StoryCollection storyColl = new StoryCollection(); storyColl.Add(testModel1); storyColl.Add(testModel2); Assert.IsTrue(storyColl.Exists(testModel2.id)); }
/// <summary> /// Gets the most popular domains. /// Measured by number of kicks per domain /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="storyCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static Dictionary<string, int> GetMostPopularDomains(int hostID, int storyCount, int year, int? month, int? day) { string cacheKey = String.Format("Zeitgeist_MostPopularDomains_{0}_{1}_{2}_{3}_{4}", hostID, storyCount, year, month, day); CacheManager<string, Dictionary<string, int>> domainCache = GetMostPopularDomainsCache(); Dictionary<string, int> domainList = domainCache[cacheKey]; if (domainList == null) { //get all stories, then loop and make our own domain list Query qry = new Query(Story.Schema); qry.OrderBy = OrderBy.Desc(Story.Columns.KickCount); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); qry.AddWhere(Story.Columns.KickCount, Comparison.GreaterOrEquals, 1); StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); domainList = new Dictionary<string, int>(); Regex rx = new Regex(@"^(?=[^&])(?:(?<scheme>[^:/?#]+):)?(?://(?<authority>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?"); foreach (Story s in stories) { Match uriMatch = rx.Match(s.Url); if (!uriMatch.Success) continue; string authority = uriMatch.Groups["authority"].Value; if (string.IsNullOrEmpty(authority)) continue; if (domainList.ContainsKey(authority)) domainList[authority] += s.KickCount; else domainList.Add(authority, s.KickCount); } //sort and trim to storyCount List<KeyValuePair<string, int>> sortedPairs = new List<KeyValuePair<string, int>>(domainList); sortedPairs.Sort( delegate(KeyValuePair<string, int> obj1, KeyValuePair<string, int> obj2) { return obj2.Value.CompareTo(obj1.Value); } ); domainList.Clear();//clear and add top X values if (sortedPairs.Count < storyCount) storyCount = sortedPairs.Count; for (int i = 0; i < storyCount; i++) domainList.Add(sortedPairs[i].Key, sortedPairs[i].Value); domainCache.Insert(cacheKey, domainList, CacheHelper.CACHE_DURATION_IN_SECONDS); } return domainList; }
public static Story FetchStoryByParameter(string columnName, object value) { //NOTE: GJ: maybe we should add support for this in SubSonic? (like rails does) StoryCollection t = new StoryCollection(); t.Load(Story.FetchByParameter(columnName, value)); if (t.Count == 0) return null; else return t[0]; }
/// <summary> /// Gets the most published users. /// Measured by number of published stories per user /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="userCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static Dictionary <string, int> GetMostPublishedUsers(int hostID, int userCount, int year, int?month, int?day) { string cacheKey = String.Format("Zeitgeist_MostPublishedUsers_{0}_{1}_{2}_{3}_{4}", hostID, userCount, year, month, day); CacheManager <string, Dictionary <string, int> > userListCache = GetMostPublishedUsersCache(); Dictionary <string, int> userList = userListCache[cacheKey]; if (userList == null) { //get all stories, then loop and make our own domain list Query qry = new Query(Story.Schema); qry.OrderBy = OrderBy.Desc(Story.Columns.UserID); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.IsPublishedToHomepage, true); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); userList = new Dictionary <string, int>(); foreach (Story s in stories) { if (userList.ContainsKey(s.User.Username)) { userList[s.User.Username] += 1; } else { userList.Add(s.User.Username, 1); } } //sort and trim to storyCount List <KeyValuePair <string, int> > sortedPairs = new List <KeyValuePair <string, int> >(userList); sortedPairs.Sort( delegate(KeyValuePair <string, int> obj1, KeyValuePair <string, int> obj2) { return(obj2.Value.CompareTo(obj1.Value)); } ); userList.Clear();//clear and add top X values if (sortedPairs.Count < userCount) { userCount = sortedPairs.Count; } for (int i = 0; i < userCount; i++) { userList.Add(sortedPairs[i].Key, sortedPairs[i].Value); } userListCache.Insert(cacheKey, userList, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(userList); }
public static void PublishStoryProcess() { // promote stories to the various hosts homepages foreach (string hostKey in HostCache.Hosts.Keys) { Host host = HostCache.Hosts[hostKey]; Trace.Write("Pub: Processing " + host.HostName); //get unkicked stories within the maximumStoryAgeInHours DateTime startDate = DateTime.Now.AddHours(-host.Publish_MinimumStoryAgeInHours); DateTime endDate = DateTime.Now.AddHours(-host.Publish_MaximumStoryAgeInHours); //now get a dataset containing all these (NOTE: perf: we could use paging here to reduce the memory footprint) StoryCollection stories = Story.GetStoriesByIsPublishedAndHostIDAndPublishedDate(host.HostID, false, endDate, startDate); Trace.Write("Pub: There are now " + stories.Count + " candidate stories."); //pass 1: remove any weak candidate stories StoryCollection candidateStories = new StoryCollection(); foreach (Story story in stories) { if (!IsWeakStory(story, host)) { candidateStories.Add(story); } } Trace.Write("Pub: There are now " + candidateStories.Count + " candidate stories."); //pass 2: calculate scores for each story SortedList <int, int> storyScoreList = new SortedList <int, int>(); foreach (Story story in candidateStories) { storyScoreList[GetStoryScore(story, host)] = story.StoryID; } //pass 3: should the top story be published? if (storyScoreList.Count > 0) { for (int i = 0; i < host.Publish_MaximumSimultaneousStoryPublishCount; i++) { if (storyScoreList.Count > i) { int storyIndex = storyScoreList.Count - 1 - i; //we have to work backwards as the lowest are first if (storyScoreList.Keys[storyIndex] >= host.Publish_MinimumStoryScore) { //publish this story Trace.Write("Pub: Publishing storyID:" + storyScoreList.Values[storyIndex]); PublishStory(storyScoreList.Values[storyIndex]); } } } } } }
/// <summary> /// Get all the stories for a given host /// </summary> /// <param name="hostID"></param> /// <returns></returns> public static StoryCollection GetAllStories(int hostID, int pageIndex, int pageSize) { Query q = Story.Query(); q.WHERE(Story.Columns.HostID, hostID).AND(Story.Columns.IsSpam, false); q.PageIndex = pageIndex; q.PageSize = pageSize; StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(q.ExecuteReader()); return stories; }
public void DataBind(StoryCollection stories, int recordCount) { this._paging = new Paging(this.KickPage.UrlParameters.PageSize, this.KickPage.UrlParameters.PageNumber, recordCount); this.Controls.Add(this.StoryList); this.Controls.Add(this.Paging); this.StoryList.DataBind(stories); if(this.KickPage.UrlParameters.StoryListSortBy != Incremental.Kick.Common.Enums.StoryListSortBy.RecentlyPromoted) { this._paging.BaseUrl = "/popular/" + this.KickPage.UrlParameters.StoryListSortBy.ToString().ToLower(); } }
public void DataBind(StoryCollection stories, int recordCount) { this._paging = new Paging(this.KickPage.UrlParameters.PageSize, this.KickPage.UrlParameters.PageNumber, recordCount); this.Controls.Add(this.StoryList); this.Controls.Add(this.Paging); this.StoryList.DataBind(stories); if (this.KickPage.UrlParameters.StoryListSortBy != Incremental.Kick.Common.Enums.StoryListSortBy.RecentlyPromoted) { this._paging.BaseUrl = "/popular/" + this.KickPage.UrlParameters.StoryListSortBy.ToString().ToLower(); } }
public static StoryCollection GetUserSubmittedStories(string userIdentifier, int hostID, int pageNumber, int pageSize) { string cacheKey = String.Format("Kick_StoryTable_UserSubmitted_{0}_{1}_{2}_{3}", userIdentifier, hostID, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetUserSubmittedStories(UserCache.GetUserID(userIdentifier), hostID, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static StoryCollection GetAllStories(bool isPublished, int hostID, int pageNumber, int pageSize) { pageSize = TrimPageSize(pageSize); string cacheKey = String.Format("StoryCollection_{0}_{1}_{2}_{3}", isPublished, hostID, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetStoriesByIsPublishedAndHostID(isPublished, hostID, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static RssChannel ConvertToRssChannel(StoryCollection stories, string title, string description, string link, Host host) { RssChannel channel = new RssChannel(); channel.Title = title; channel.Description = description; channel.Link = new System.Uri(link); channel.Language = "en-us"; channel.Generator = host.SiteTitle + " - " + host.TagLine; channel.Docs = ""; channel.TimeToLive = 30; channel.Copyright = "Atweb Publishing Ltd."; if (stories.Count == 0) { RssItem item = new RssItem(); item.Title = " "; item.Description = " "; item.PubDate = DateTime.Now.ToUniversalTime(); channel.Items.Add(item); } else { foreach (Story story in stories) { string storyUrl = host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, host.HostID).CategoryIdentifier); //TODO: GJ: add category info RssItem item = new RssItem(); item.Title = story.Title; item.Description = story.Description + " <br /><br /><br />" + Incremental.Common.Web.Helpers.ControlHelper.RenderControl(new Incremental.Kick.Web.Controls.StoryDynamicImage(story.Url, host)); item.PubDate = story.PublishedOn.ToUniversalTime(); RssGuid guid = new RssGuid(); guid.Name = storyUrl; guid.PermaLink = true; item.Guid = guid; item.Link = new Uri(storyUrl); channel.Items.Add(item); } } return(channel); }
public async Task <int[]> GetBestStoryIdsAsync() { List <int> lstBestStoryIds = null; StoryCollection colStory = new StoryCollection(); Uri uri = new Uri(HNBaseUrl + "/beststories.json"); RequestResult requestResult = await HttpHelper.SendRequestAsync(uri); if (requestResult.IsSuccess) { JArray rootObject = (JArray)JsonConvert.DeserializeObject(requestResult.Content); lstBestStoryIds = rootObject.ToObject <List <int> >(); } return(lstBestStoryIds.ToArray()); }
public static string GetStoryIdentifier(string title) { title = Regex.Replace(title, @"[^\w\s]", "_"); title = title.Replace(" ", "_"); while (Regex.Match(title, "__").Success) { title = Regex.Replace(title, "__", "_"); } if (title.Substring(0, 1) == "_") { title = title.Substring(1, title.Length - 1); } if (title.Substring(title.Length - 1, 1) == "_") { title = title.Substring(0, title.Length - 1); } string identifier = title; //ensure that it is unique in the database //NOTE: we could use a datestamp to make it unique int iteration = 0; while (iteration < 10) { if (iteration > 0) { identifier = title + "_" + iteration; } StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByParameter(Story.Columns.StoryIdentifier, identifier)); if (stories.Count == 0) { return(identifier); } iteration++; } throw new Exception("The story identifier [" + title + "] was not unique"); }
// Use this for initialization void Awake() { string json; // Load actions json = Loader.Load(Application.dataPath + "/Data/actions.json"); ActionCollection actionCollection = JsonUtility.FromJson <ActionCollection>(json); actions = actionCollection.data; // Load expressions json = Loader.Load(Application.dataPath + "/Data/expressions.json"); expressions = ExpressionCollection.CreateExpressionList(json); // Load stories json = Loader.Load(Application.dataPath + "/Data/stories.json"); stories = StoryCollection.CreateStoryList(json); }
public static StoryCollection GetPopularStories(int hostID, bool isPublished, StoryListSortBy sortBy, int pageNumber, int pageSize) { pageSize = TrimPageSize(pageSize); string cacheKey = String.Format("StoryCollection_{0}_{1}_{2}_{3}_{4}", hostID, isPublished, sortBy, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetPopularStories(hostID, isPublished, sortBy, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public async Task <StoryCollection> GetBestStoriesAsync(int[] storyIds) { StoryCollection colStory = new StoryCollection(); Uri uri = new Uri(HNBaseUrl + "/beststories.json"); for (var i = 0; i < storyIds.Length; i++) { Story story = await GetStoryAsync(storyIds[i]); if (story != null) { colStory.Add(story); } } return(colStory); }
public static Library InitializeLibrary() { var story1 = new Story("Story1", StoryType.Novella, true, "Petko"); var story2 = new Story("Story2", StoryType.ShortStory, false, "Stanko"); var story3 = new Story("Story3", StoryType.Novellette, true, "Cvetko"); var story4 = new Story("Story4", StoryType.ShortStory, true, "Petko"); var story5 = new Story("Story5", StoryType.Novella, false, "Author1"); var story6 = new Story("Story6", StoryType.Novellette, true, "Petko"); var story7 = new Story("Story7", StoryType.Novella, false, "Author1"); var novel1 = new Novel("AuthorN", "Novel1", TypeOfEdition.EBook, 400); var novel2 = new Novel("AuthorN2", "Novel2", TypeOfEdition.Paperback, 270) { Series = "Novel", SeriesNumber = 2 }; var storyCollection1 = new StoryCollection("Petko", "Zbirka1", TypeOfEdition.Hardcover, 832); var storyCollection2 = new StoryCollection("Author1", "Zbirka2", TypeOfEdition.EBook, 327); storyCollection1.Stories.Add(story1); storyCollection1.Stories.Add(story4); storyCollection1.Stories.Add(story6); storyCollection2.Stories.Add(story5); storyCollection2.Stories.Add(story7); var anthology = new Anthology("Editorce", "Anthology", TypeOfEdition.Audiobook, 432); var anthology2 = new Anthology("Editor2", "Anthology2", TypeOfEdition.EBook, 385); anthology.Stories.Add(story3); anthology.Stories.Add(story1); anthology2.Stories.Add(story2); anthology2.Stories.Add(story1); anthology2.Stories.Add(story6); Library library = new Library(); library.Books = new List <IBook> { novel1, novel2, storyCollection1, storyCollection2, anthology, anthology2 }; return(library); //throw new NotImplementedException(); }
public static RssChannel ConvertToRssChannel(StoryCollection stories, string title, string description, string link, Host host) { RssChannel channel = new RssChannel(); channel.Title = title; channel.Description = description; channel.Link = new System.Uri(link); channel.Language = "en-us"; channel.Generator = host.SiteTitle + " - " + host.TagLine; channel.Docs = ""; channel.TimeToLive = 30; channel.Copyright = "Atweb Publishing Ltd."; if (stories.Count == 0) { RssItem item = new RssItem(); item.Title = " "; item.Description = " "; item.PubDate = DateTime.Now.ToUniversalTime(); channel.Items.Add(item); } else { foreach (Story story in stories) { string storyUrl = host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, host.HostID).CategoryIdentifier); //TODO: GJ: add category info RssItem item = new RssItem(); item.Title = story.Title; item.Description = story.Description + " <br /><br /><br />" + Incremental.Common.Web.Helpers.ControlHelper.RenderControl(new Incremental.Kick.Web.Controls.StoryDynamicImage(story.Url, host)); item.PubDate = story.PublishedOn.ToUniversalTime(); RssGuid guid = new RssGuid(); guid.Name = storyUrl; guid.PermaLink = true; item.Guid = guid; item.Link = new Uri(storyUrl); channel.Items.Add(item); } } return channel; }
/// <summary> /// Searches the index for stories kicked by a given user /// </summary> /// <param name="query"></param> /// <param name="username"></param> /// <param name="hostId"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public static StoryCollection GetStoryCollectionSearchResultsByUser(string query, string username, string sortField, bool sortReversed, int hostId, int page, int pageSize) { string cacheKey = string.Format("SearchUserStoryCollection_{0}_{1}_{2}_{3}_{4}_{5}_{6}", CleanUpQuery(query), hostId, page, pageSize, username, sortField, sortReversed); string cacheCountKey = string.Format("SearchUserStoryCollectionCount_{0}_{1}_{2}", CleanUpQuery(query), hostId, username); CacheManager <string, StoryCollection> cache = GetSearchStoryCollectionCache(); StoryCollection results = cache[cacheKey]; if (results == null) { int totalNumberResults = 0; SearchQuery searchQuery = new SearchQuery(); results = searchQuery.SearchIndex(hostId, query, username, page, pageSize, sortField, sortReversed, out totalNumberResults); if (results != null) { cache.Insert(cacheKey, results, CacheHelper.CACHE_DURATION_IN_SECONDS); } //add to the cache containing the search results counts, we dont want to have to call the //the search twice since we already have this value in this method call. CacheManager <string, int?> cacheCount = GetSearchStoryCountCache(); if (cacheCount.ContainsKey(cacheCountKey)) { cacheCount.Remove(cacheCountKey); } cacheCount.Insert(cacheCountKey, totalNumberResults, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(results); }
private static Library InitializeLibrary() { Library library = new Library("National Library"); var storyCollection = new StoryCollection("100 selected stories by O Henry", TypeOfBook.EBook, 338, "O.Henry"); var shortStory1 = new Story { Title = "The Gift of the Magi", AuthorName = "O.Henry", StoryType = StoryType.ShortStory, IsItOriginalStory = true }; var shortStory2 = new Story { Title = "A Cosmopolite in a Café", AuthorName = "O.Henry", StoryType = StoryType.ShortStory, IsItOriginalStory = true }; var shortStory3 = new Story { Title = "Between Rounds", AuthorName = "O.Henry", StoryType = StoryType.ShortStory, IsItOriginalStory = true }; storyCollection.Stories = new List <Story> { shortStory1, shortStory2, shortStory3 }; var anthology = new Anthology("Zombie vs unicorns", TypeOfBook.Hardcover, 418, "Holy black"); var story1 = new Story { Title = "Love will tear us apart", AuthorName = "Alaya johnson", StoryType = StoryType.Novella, IsItOriginalStory = true }; var story2 = new Story { Title = "Love will tear us apart", AuthorName = "Alaya johnson", StoryType = StoryType.Novella, IsItOriginalStory = true }; anthology.Stories = new List <Story> { story1, story2 }; library.AddBook(new Novel("To kill a mockingbird", TypeOfBook.Papaerback, 384, "Harper Lee")); library.AddBook(new Novel("The Fellowship of the Ring", TypeOfBook.EBook, 423, "J. R. R. Tolkien") { Series = "The lord of the rings", SeriesNumber = 1 }); library.AddBook(storyCollection); library.AddBook(anthology); return(library); }
public static StoryCollection GetSimilarStoryCollection(int hostId, int storyId) { string cacheKey = string.Format("SimilarStoryCollection_{0}_{1}", storyId, hostId); CacheManager <string, StoryCollection> cache = GetSimilarStoriesCache(); StoryCollection results = cache[cacheKey]; if (results == null) { SimilarStories similarStories = new SimilarStories(); results = similarStories.Find(hostId, storyId); if (results != null) { cache.Insert(cacheKey, results, CacheHelper.CACHE_DURATION_IN_SECONDS); } } return(results); }
private static void AddMissingChallenges(StoryCollection stories, List <string> processedChallenges, ApplicationDbContext context) { foreach (var story in stories) { var challengeName = ExtractChallengeName(story.Filename); if (processedChallenges.IndexOf(challengeName) == -1 && _context.Challenge.FirstOrDefault(item => item.Name == challengeName) == null && story.StoryType != StoryType.Feature) { // add this missing challenge to the db var data = GetPointsForStory(stories, challengeName); _context.Challenge.Add(new gdbcLeaderBoard.Models.Challenge { Name = challengeName, Points = data.Item1, IsBonus = data.Item2, UniqueTag = data.Item3 }); } } }
/// <summary> /// Gets the most kicked stories. /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="storyCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static StoryCollection GetMostPopularStories(int hostID, int storyCount, int year, int?month, int?day) { string cacheKey = String.Format("Zeitgeist_MostPopular_{0}_{1}_{2}_{3}_{4}", hostID, storyCount, year, month, day); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { Query qry = new Query(Story.Schema); qry.Top = storyCount.ToString(); qry.OrderBy = OrderBy.Desc(Story.Columns.KickCount); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); qry.AddWhere(Story.Columns.KickCount, Comparison.GreaterOrEquals, 1); stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
/// <summary> /// Returns a StoryCollection containing the stories that match for the given /// search term. The stories are returned in the correct order as given /// by the lucene results. /// </summary> /// <param name="results"></param> /// <returns></returns> internal static StoryCollection LoadStorySearchResults(IList <int> results) { if (results.Count == 0) { return(null); } StoryCollection stories = Story.GetStoriesByIds(results); //the stories are not returned in the hit order lucene found //the matches, the order is storyId asc. We need to correct //the order so the collection is correctly order as per the //hits result from lucene StoryCollection searchResults = new StoryCollection(); foreach (int i in results) { Story s = (Story)stories.Find(i); searchResults.Add(s); } return(searchResults); }
// [rgn] Public Methods (9) /// <summary> /// Gets the most commented on stories. /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="storyCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static StoryCollection GetMostCommentedOnStories(int hostID, int storyCount, int year, int? month, int? day) { string cacheKey = String.Format("Zeitgeist_MostCommentedOn_{0}_{1}_{2}_{3}_{4}", hostID, storyCount, year, month, day); CacheManager<string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { Query qry = new Query(Story.Schema); qry.Top = storyCount.ToString(); qry.OrderBy = OrderBy.Desc(Story.Columns.CommentCount); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); qry.AddWhere(Story.Columns.CommentCount, Comparison.GreaterOrEquals, 1); stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return stories; }
private static Tuple <int, bool, string> GetPointsForStory(StoryCollection stories, string challengeName) { var story = stories.FirstOrDefault(item => item.Id == challengeName); var points = 0; var isBonus = false; var uniqueTag = ""; if (story == null) { Console.WriteLine($"Cannot process story for challenge '{challengeName}'"); return(new Tuple <int, bool, string>(points, isBonus, uniqueTag)); } var pointsProperty = story.Properties.FirstOrDefault(item => item.Key == "effort"); if (!string.IsNullOrEmpty(pointsProperty.Key)) { int.TryParse(pointsProperty.Value, out points); } var isBonusProperty = story.Properties.FirstOrDefault(item => item.Key == "bonus"); if (!string.IsNullOrEmpty(pointsProperty.Key)) { bool.TryParse(isBonusProperty.Value, out isBonus); } var uniqueTagProperty = story.Properties.FirstOrDefault(item => item.Key == "code"); if (!string.IsNullOrEmpty(uniqueTagProperty.Key)) { uniqueTag = uniqueTagProperty.Value; } return(new Tuple <int, bool, string>(points, isBonus, uniqueTag)); }
// [rgn] Public Methods (1) /// <summary> /// Binds the data /// </summary> /// <param name="stories">The stories.</param> public void DataBind(StoryCollection stories) { this._stories = stories; }
public static StoryCollection GetPopularStories(int hostID, bool isPublished, StoryListSortBy sortBy, int pageIndex, int pageSize) { Query query = GetStoryQuery(hostID, isPublished, GetStartDate(sortBy), DateTime.Now); query = query.ORDER_BY(Story.Columns.KickCount, "DESC"); query.PageIndex = pageIndex; query.PageSize = pageSize; StoryCollection stories = new StoryCollection(); stories.Load(query.ExecuteReader()); return stories; }
/// <summary> /// Renders the story list items. /// </summary> /// <param name="writer">The writer.</param> /// <param name="title">The title.</param> /// <param name="reader">The reader.</param> private void RenderStoryListItems(HtmlTextWriter writer, StoryCollection stories, string valueCountField, string title, string itemType) { //render top 10 lists writer.RenderBeginTag(HtmlTextWriterTag.H3); writer.Write(title); writer.Write(" for "); if (Month == null) writer.Write(Year); else if (Day == null) writer.Write(new DateTime(Year.Value, Month.Value, 1).ToString("MMMM yyyy")); else writer.Write(new DateTime(Year.Value, Month.Value, Day.Value).ToString("MMMM d, yyyy")); writer.RenderEndTag(); //just plain OL with story title links writer.RenderBeginTag(HtmlTextWriterTag.Ol); foreach (Story s in stories) { string kickStoryUrl = UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, s.StoryIdentifier, s.Category.CategoryIdentifier); writer.RenderBeginTag(HtmlTextWriterTag.Li); writer.WriteBeginTag("a"); writer.WriteAttribute("href", kickStoryUrl); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(s.Title); writer.WriteEndTag("a"); writer.Write(" (" + SubSonic.Sugar.Strings.Pluralize(s.GetColumnValue<int>(valueCountField), itemType) + ")"); writer.RenderEndTag(); } writer.RenderEndTag(); if (stories.Count.Equals(0)) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write(this.NoDataCaption); writer.RenderEndTag(); } //do story summary in OL //foreach (Story s in stories) //{ // string kickStoryUrl = UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, // s.StoryIdentifier, // s.Category.CategoryIdentifier); // writer.RenderBeginTag(HtmlTextWriterTag.Li); // StorySummary ss = new StorySummary(); // ss.ShowFullSummary = false; // ss.DataBind(s); // ss.RenderControl(writer); // writer.RenderEndTag(); //} }
static void Main(string[] args) { Library thousandBooks = new Library("Thousand Books"); Novels ulysses = new Novels("James Joyce", "Ulysses", EditionType.Hardcover, 345, false); Novels theGreatGatsby = new Novels("F. Scott Fitzgerald", "The Great Gatsby", EditionType.EBook, 2222, false); Novels lolita = new Novels("Vladimir Nabokov", "Lolita", EditionType.AudioBook, 422, false); Novels catch22 = new Novels("Joseph Heller", "Catch 22", EditionType.Paperback, 356, false); Novels harryPoter = new Novels(" J. K. Rowling", "Harry Potter", EditionType.Hardcover, 4522, false); Novels harryPotterandtheHalfBloodPrince = new Novels("J.K. Rowling", "Harry Potter and the Half-Blood Prince", EditionType.Hardcover, 642, true); Novels harryPotterandTheGobletOfFire = new Novels("J.K. Rowling", "Harry Potter and the Goblet of Fire", EditionType.Hardcover, 922, true); Novels harryPoterAndTheChamberOfSeacret = new Novels("J.K. Rowling", "Harry Potter And The Chamber Of Seacret", EditionType.Hardcover, 399, true); harryPoter.AddToSeries(harryPoterAndTheChamberOfSeacret); harryPoter.AddToSeries(harryPotterandTheGobletOfFire); harryPoter.AddToSeries(harryPotterandtheHalfBloodPrince); StoryCollection sticks = new StoryCollection("Unknown", "Sticks", StoryType.ShortStory, true); StoryCollection victoryLap = new StoryCollection("Unknown", "Victory Lap", StoryType.Novellete, true); StoryCollections tenthOfDecember = new StoryCollections("George Saunders", "Tenth of December", EditionType.Paperback, 1244); tenthOfDecember.AddStory(sticks); tenthOfDecember.AddStory(victoryLap); Anthology fragileThings = new Anthology("Neil Gaiman", "fantastic", EditionType.Hardcover, 360, "Fragile Things"); StoryAnthology closingTime = new StoryAnthology("Closing Time", "Robert Aickman", StoryType.ShortStory, true); StoryAnthology aLoveStory = new StoryAnthology("A Love Story", "Waren Pleece", StoryType.ShortStory, true); fragileThings.AddStory(closingTime); fragileThings.AddStory(aLoveStory); thousandBooks.AddBook(harryPoter); thousandBooks.AddBook(tenthOfDecember); thousandBooks.AddBook(fragileThings); var allBooks = thousandBooks.GetBooks(); //------------------------------------------------------------------------------------ string input = Console.ReadLine(); if (input == "novela") { PrintNovela(allBooks); } Console.WriteLine("\n----------------"); if (input == "coll") { PrintCollectionStory(allBooks); } Console.WriteLine("\n----------------"); if (input == "ant") { PrintAnthology(allBooks); } Console.WriteLine("\n----------------"); //------------------------------------------------------------------------------------ // Print PrintCollectionStory(allBooks); Console.WriteLine("\n----------------"); Console.WriteLine("Anthology : \n"); PrintAnthology(allBooks); Console.WriteLine("\n----------------"); Console.WriteLine("Novelas : \n"); PrintNovela(allBooks); Console.WriteLine("\n----------------"); Console.ReadLine(); }
public StoryCollection FetchByID(object StoryID) { StoryCollection coll = new StoryCollection().Where("StoryID", StoryID).Load(); return coll; }
/// <summary> /// Renders the story list items. /// </summary> /// <param name="writer">The writer.</param> /// <param name="title">The title.</param> /// <param name="reader">The reader.</param> private void RenderStoryListItems(HtmlTextWriter writer, StoryCollection stories, string valueCountField, string title, string itemType) { //render top 10 lists writer.RenderBeginTag(HtmlTextWriterTag.H3); writer.Write(title); writer.Write(" for "); if (Month == null) { writer.Write(Year); } else if (Day == null) { writer.Write(new DateTime(Year.Value, Month.Value, 1).ToString("MMMM yyyy")); } else { writer.Write(new DateTime(Year.Value, Month.Value, Day.Value).ToString("MMMM d, yyyy")); } writer.RenderEndTag(); //just plain OL with story title links writer.RenderBeginTag(HtmlTextWriterTag.Ol); foreach (Story s in stories) { string kickStoryUrl = UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, s.StoryIdentifier, s.Category.CategoryIdentifier); writer.RenderBeginTag(HtmlTextWriterTag.Li); writer.WriteBeginTag("a"); writer.WriteAttribute("href", kickStoryUrl); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(s.Title); writer.WriteEndTag("a"); writer.Write(" (" + SubSonic.Sugar.Strings.Pluralize(s.GetColumnValue <int>(valueCountField), itemType) + ")"); writer.RenderEndTag(); } writer.RenderEndTag(); if (stories.Count.Equals(0)) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write(this.NoDataCaption); writer.RenderEndTag(); } //do story summary in OL //foreach (Story s in stories) //{ // string kickStoryUrl = UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, // s.StoryIdentifier, // s.Category.CategoryIdentifier); // writer.RenderBeginTag(HtmlTextWriterTag.Li); // StorySummary ss = new StorySummary(); // ss.ShowFullSummary = false; // ss.DataBind(s); // ss.RenderControl(writer); // writer.RenderEndTag(); //} }
public static void PublishStoryProcess() { // promote stories to the various hosts homepages foreach (string hostKey in HostCache.Hosts.Keys) { Host host = HostCache.Hosts[hostKey]; Trace.Write("Pub: Processing " + host.HostName); //get unkicked stories within the maximumStoryAgeInHours DateTime startDate = DateTime.Now.AddHours(-host.Publish_MinimumStoryAgeInHours); DateTime endDate = DateTime.Now.AddHours(-host.Publish_MaximumStoryAgeInHours); //now get a dataset containing all these (NOTE: perf: we could use paging here to reduce the memory footprint) StoryCollection stories = Story.GetStoriesByIsPublishedAndHostIDAndPublishedDate(host.HostID, false, endDate, startDate); Trace.Write("Pub: There are now " + stories.Count + " candidate stories."); //pass 1: remove any weak candidate stories StoryCollection candidateStories = new StoryCollection(); foreach (Story story in stories) { if (!IsWeakStory(story, host)) candidateStories.Add(story); } Trace.Write("Pub: There are now " + candidateStories.Count + " candidate stories."); //pass 2: calculate scores for each story SortedList<int, int> storyScoreList = new SortedList<int, int>(); foreach (Story story in candidateStories) { storyScoreList[GetStoryScore(story, host)] = story.StoryID; } //pass 3: should the top story be published? if (storyScoreList.Count > 0) { for (int i = 0; i < host.Publish_MaximumSimultaneousStoryPublishCount; i++) { if (storyScoreList.Count > i) { int storyIndex = storyScoreList.Count - 1 - i; //we have to work backwards as the lowest are first if (storyScoreList.Keys[storyIndex] >= host.Publish_MinimumStoryScore) { //publish this story Trace.Write("Pub: Publishing storyID:" + storyScoreList.Values[storyIndex]); PublishStory(storyScoreList.Values[storyIndex]); } } } } } }
public static StoryCollection GetUserTaggedStories(int? tagID, int userID, int hostID, int pageNumber, int pageSize) { StoryCollection stories = new StoryCollection(); if (tagID.HasValue) { stories.Load(SPs.Kick_GetPagedStoriesByTagIDAndHostIDAndUserID(tagID, hostID, userID, pageNumber, pageSize).GetReader()); } return stories; }
private static void UpdateChallenge(string sourceDirectory, string dropBoxLink, List <gdbcLeaderBoard.Models.Challenge> challenges, StoryCollection stories) { var challengeName = ExtractChallengeName(sourceDirectory); var challenge = challenges.FirstOrDefault(item => item.Name == challengeName); if (challenge == null) { challenge = new gdbcLeaderBoard.Models.Challenge { Name = challengeName }; _context.Challenge.Add(challenge); } // update properties challenge.HelpUrl = UpdateLinkToForceDownload(dropBoxLink); // get info from parsed stories: var data = GetPointsForStory(stories, challengeName); challenge.Points = data.Item1; challenge.IsBonus = data.Item2; challenge.UniqueTag = data.Item3; Console.Write($"Updating challenge '{sourceDirectory}', points: {challenge.Points}, bonus: {challenge.IsBonus}"); Console.WriteLine(); }
/// <summary> /// Returns a StoryCollection containing the stories that match for the given /// search term. The stories are returned in the correct order as given /// by the lucene results. /// </summary> /// <param name="results"></param> /// <returns></returns> internal static StoryCollection LoadStorySearchResults(IList<int> results) { if (results.Count == 0) return null; StoryCollection stories = Story.GetStoriesByIds(results); //the stories are not returned in the hit order lucene found //the matches, the order is storyId asc. We need to correct //the order so the collection is correctly order as per the //hits result from lucene StoryCollection searchResults = new StoryCollection(); foreach (int i in results) { Story s = (Story)stories.Find(i); searchResults.Add(s); } return searchResults; }
public static StoryCollection GetUserSubmittedStories(int userID, int hostID, int pageNumber, int pageSize) { StoryCollection stories = new StoryCollection(); stories.Load(SPs.Kick_GetPagedSubmittedStoriesByUserIDAndHostID(userID, hostID, pageNumber, pageSize).GetReader()); return stories; }
/// <summary> /// Returns a StoryCollection of stories that have been modified after the /// given DateTime value /// </summary> /// <remarks>this is used by lucene to create an incremental update of the search /// index without having to do a full index again</remarks> /// <param name="updatedAfter"></param> /// <returns></returns> public static StoryCollection GetUpdatedStories(int hostID, DateTime updatedAfter, int pageIndex, int pageSize) { Query q = Story.Query(); q.WHERE(Story.Columns.HostID, hostID).AND(Story.Columns.UpdatedOn, Comparison.GreaterOrEquals, updatedAfter); q.PageIndex = pageIndex; q.PageSize = pageSize; StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(q.ExecuteReader()); return stories; }
public static StoryCollection GetStoriesByIsPublishedAndHostIDAndPublishedDate(int hostID, bool isPublished, DateTime startDate, DateTime endDate) { StoryCollection stories = new StoryCollection(); stories.Load(GetStoryQuery(hostID, isPublished, startDate, endDate).ExecuteReader()); return stories; }
public static string GetStoryIdentifier(string title) { title = Regex.Replace(title, @"[^\w\s]", "_"); title = title.Replace(" ", "_"); while (Regex.Match(title, "__").Success) title = Regex.Replace(title, "__", "_"); if (title.Substring(0, 1) == "_") title = title.Substring(1, title.Length - 1); if (title.Substring(title.Length - 1, 1) == "_") title = title.Substring(0, title.Length - 1); string identifier = title; //ensure that it is unique in the database //NOTE: we could use a datestamp to make it unique int iteration = 0; while (iteration < 10) { if (iteration > 0) identifier = title + "_" + iteration; StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByParameter(Story.Columns.StoryIdentifier, identifier)); if (stories.Count == 0) return identifier; iteration++; } throw new Exception("The story identifier [" + title + "] was not unique"); }
/// <summary> /// Returns a StoryCollection for a given IList of storyIds /// </summary> /// <param name="storyId"></param> /// <returns></returns> public static StoryCollection GetStoriesByIds(IList<int> storyId) { Query q = Story.Query(); object[] storyIdArray = new object[storyId.Count]; for (int i = 0; i < storyId.Count; i++) { storyIdArray[i] = storyId[i]; } q.IN("storyID", storyIdArray); StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(q.ExecuteReader()); return stories; }
public void DataBind(StoryCollection stories) { this.relatedStory = stories; }
public StoryCollection FetchByQuery(Query qry) { StoryCollection coll = new StoryCollection(); coll.LoadAndCloseReader(qry.ExecuteReader()); return coll; }
/// <summary> /// Gets the most published users. /// Measured by number of published stories per user /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="userCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static Dictionary<string, int> GetMostPublishedUsers(int hostID, int userCount, int year, int? month, int? day) { string cacheKey = String.Format("Zeitgeist_MostPublishedUsers_{0}_{1}_{2}_{3}_{4}", hostID, userCount, year, month, day); CacheManager<string, Dictionary<string, int>> userListCache = GetMostPublishedUsersCache(); Dictionary<string, int> userList = userListCache[cacheKey]; if (userList == null) { //get all stories, then loop and make our own domain list Query qry = new Query(Story.Schema); qry.OrderBy = OrderBy.Desc(Story.Columns.UserID); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.IsPublishedToHomepage, true); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); userList = new Dictionary<string, int>(); foreach (Story s in stories) { if (userList.ContainsKey(s.User.Username)) userList[s.User.Username] += 1; else userList.Add(s.User.Username, 1); } //sort and trim to storyCount List<KeyValuePair<string, int>> sortedPairs = new List<KeyValuePair<string, int>>(userList); sortedPairs.Sort( delegate(KeyValuePair<string, int> obj1, KeyValuePair<string, int> obj2) { return obj2.Value.CompareTo(obj1.Value); } ); userList.Clear();//clear and add top X values if (sortedPairs.Count < userCount) userCount = sortedPairs.Count; for (int i = 0; i < userCount; i++) userList.Add(sortedPairs[i].Key, sortedPairs[i].Value); userListCache.Insert(cacheKey, userList, CacheHelper.CACHE_DURATION_IN_SECONDS); } return userList; }
// [rgn] Public Methods (1) /// <summary> /// Binds the data. /// </summary> /// <param name="hostId">The host id.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> public void DataBind(int hostId, int? year, int? month, int? day) { //don't do data bind if year is null //just show listing if (year == null) return; this.Month = month; this.Year = year; this.Day = day; _mostKickedStories = ZeitgeistCache.GetMostPopularStories(hostId, this.NumberOfItems, this.Year.Value, this.Month, this.Day); _mostCommentedOnStories = ZeitgeistCache.GetMostCommentedOnStories(hostId, this.NumberOfItems, this.Year.Value, this.Month, this.Day); _mostUsedTags = ZeitgeistCache.GetMostUsedTags(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPopularDomains = ZeitgeistCache.GetMostPopularDomains(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPublishedDomains = ZeitgeistCache.GetMostPublishedDomains(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _mostPublishedUsers = ZeitgeistCache.GetMostPublishedUsers(hostId, this.numberOfItems, this.Year.Value, this.Month, this.Day); _storiesSubmittedCount = ZeitgeistCache.GetNumberOfStoriesSubmitted(hostId, this.Year.Value, this.Month, this.Day); _storiesPublishedCount = ZeitgeistCache.GetNumberOfStoriesPublished(hostId, this.Year.Value, this.Month, this.Day); _kicksCount = ZeitgeistCache.GetNumberOfKicks(hostId, this.Year.Value, this.Month, this.Day); _commentsCount = ZeitgeistCache.GetNumberOfComments(hostId, this.Year.Value, this.Month, this.Day); _userRegistrationCount = ZeitgeistCache.GetNumberOfUserRegistrations(hostId, this.Year.Value, this.Month, this.Day); }
/// <summary> /// Loops thro a list of stories and adds them to the index. If the crawl is an incremental /// update then first the story is removed then added again. /// </summary> /// <param name="modifier">IndexModifer used to update the index</param> /// <param name="isIncrementalCrawl">bool indicating if the stories should /// be removed from the existing index before being added again.</param> /// <param name="stories">StoryCollection containing the stories to add/update /// in the index</param> private void AddStoriesToIndex(IndexModifier modifier, bool isIncrementalCrawl, StoryCollection stories) { if (isIncrementalCrawl) { //remove the stories from the index that have been updated Log.DebugFormat("Updating index, removing {0} stories", stories.Count); foreach (Story s in stories) { Term existingItem = new Term("id", s.StoryID.ToString()); int j = modifier.DeleteDocuments(existingItem); } } //add the new documents Log.DebugFormat("Adding batch of {0} stories to the index", stories.Count); foreach (Story story in stories) { //spam stories shouldnt be added to the index if (story.IsSpam) continue; Document doc = new Document(); doc.Add(new Field("url", story.Url, Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("title", story.Title, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES)); doc.Add(new Field("description", story.Description, Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("users", GetUserWhoKickedSearchString(story), Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("category", story.Category.Name, Field.Store.NO, Field.Index.TOKENIZED)); doc.Add(new Field("tags", GetStoryTags(story), Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES)); doc.Add(new Field("id", story.StoryID.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("kickCount", story.KickCount.ToString(), Field.Store.NO, Field.Index.UN_TOKENIZED)); doc.Add(new Field("dateAdded", DateField.DateToString(story.CreatedOn), Field.Store.NO, Field.Index.UN_TOKENIZED)); modifier.AddDocument(doc); Log.DebugFormat("StoryId {0} added to index", story.StoryID); } }
public static StoryCollection GetStoriesByIsPublishedAndHostID(bool isPublished, int hostID, int pageIndex, int pageSize) { Query query = GetStoryQuery(hostID, isPublished); query = query.ORDER_BY(Story.Columns.PublishedOn, "DESC"); query.PageIndex = pageIndex; query.PageSize = pageSize; StoryCollection stories = new StoryCollection(); stories.Load(query.ExecuteReader()); return stories; }