public SearchPostCollector(BaconManager baconMan, string searchTerm, PostSearchSorts sort = PostSearchSorts.Relevance, PostSearchTimes time = PostSearchTimes.AllTime, string subreddit = null, string authorFilter = null, string websiteFilter = null, string selftextFilter = null, string isSelfPost = null, string isNsfw = null) : base(baconMan, "SearchSubredditCollector") { m_baconMan = baconMan; // Add the subreddit if needed if (!String.IsNullOrWhiteSpace(subreddit)) { searchTerm += $" subreddit:{subreddit}"; } // Add the author if needed if (!String.IsNullOrWhiteSpace(authorFilter)) { searchTerm += $" author:{authorFilter}"; } // Add the website if needed if (!String.IsNullOrWhiteSpace(websiteFilter)) { searchTerm += $" site:{websiteFilter}"; } // Add the selftext if needed if (!String.IsNullOrWhiteSpace(selftextFilter)) { searchTerm += $" selftext:{selftextFilter}"; } // Add the is self if needed if (!String.IsNullOrWhiteSpace(isSelfPost)) { searchTerm += $" self:{isSelfPost}"; } // Add the nsfw if needed if (!String.IsNullOrWhiteSpace(isNsfw)) { searchTerm += $" nsfw:{isNsfw}"; } // Encode the query searchTerm = WebUtility.UrlEncode(searchTerm); string sortString = PostSortToString(sort); string timeString = PostTimeToString(time); // Set up the list helper InitListHelper($"/search.json", false, false, $"q={searchTerm}&sort={sortString}&t={timeString}"); }
public static string PostSortToString(PostSearchSorts sort) { switch (sort) { default: case PostSearchSorts.Relevance: return("relevance"); case PostSearchSorts.New: return("new"); case PostSearchSorts.Top: return("top"); case PostSearchSorts.Comments: return("comments"); } }
/// <summary> /// Creates a new collector and starts a search. /// </summary> /// <param name="searchTerm"></param> private void DoPostSearch(string searchTerm) { // Get all of the filters. PostSearchSorts sort = GetCurrentPostSort(); PostSearchTimes times = GetCurrentPostTime(); string subredditFilter = ui_postSubreddit.Text; string authorFilter = ui_postUserName.Text; string websiteFilter = ui_postWebsite.Text; string selftextFilter = ui_postSelfText.Text; string isSelfPost = ui_postIsSelf.SelectedIndex == 0 ? String.Empty : (ui_postIsSelf.SelectedIndex == 1 ? "yes" : "no"); string isNsfw = ui_postIsNsfw.SelectedIndex == 0 ? String.Empty : (ui_postIsNsfw.SelectedIndex == 1 ? "yes" : "no"); lock (this) { m_currentPostCollector = new SearchPostCollector(App.BaconMan, searchTerm, sort, times, subredditFilter, authorFilter, websiteFilter, selftextFilter, isSelfPost, isNsfw); m_currentPostCollector.OnCollectionUpdated += CurrentPostCollector_OnCollectionUpdated; m_currentPostCollector.OnCollectorStateChange += CurrentPostCollector_OnCollectorStateChange; m_currentPostCollector.Update(true); } }