diff --git a/app/logical/popular_search_service.rb b/app/logical/popular_search_service.rb index 4a2c55527..ecf40478a 100644 --- a/app/logical/popular_search_service.rb +++ b/app/logical/popular_search_service.rb @@ -8,7 +8,7 @@ class PopularSearchService end def each_search(limit = 100, &block) - fetch_data.scan(/(.+?) (\d+)\.0\n/).slice(0, limit).each(&block) + fetch_data.to_s.scan(/(.+?) (\d+)\.0\n/).slice(0, limit).each(&block) end def fetch_data diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index 0ed5b3974..4b2dba0d5 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -132,6 +132,10 @@ class SavedSearch < ActiveRecord::Base rename_listbooru(user_id, old_category, new_category) end + def self.categories_for(user) + user.saved_searches.pluck("distinct category") + end + def normalize self.category = SavedSearch.normalize_category(category) if category self.tag_query = SavedSearch.normalize(tag_query) diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb index 9ce17c617..8f26d3ef3 100644 --- a/app/presenters/post_set_presenters/post.rb +++ b/app/presenters/post_set_presenters/post.rb @@ -19,6 +19,8 @@ module PostSetPresenters related_tags_for_single(post_set.unordered_tag_array.first) elsif post_set.tag_string =~ /(?:^|\s)(?:#{Tag::SUBQUERY_METATAGS}):\S+/ calculate_related_tags_from_post_set + elsif post_set.tag_string =~ /search:/ + saved_search_tags elsif post_set.is_empty_tag? popular_tags else @@ -52,6 +54,10 @@ module PostSetPresenters RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first) end + def saved_search_tags + SavedSearch.categories_for(CurrentUser.user).map {|x| "search:#{x}"} + end + def tag_list_html(template, options = {}) tag_set_presenter.tag_list_html(template, options) end diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 1592ec583..dfe64eb90 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -111,9 +111,7 @@ Appeals <%= presenter.appeal_count(self) %> - <% end %> - <% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %> Flags <%= presenter.flag_count(self) %> @@ -145,7 +143,18 @@ <% end %> - <% if CurrentUser.user.id == user.id %> + <% if CurrentUser.id == user.id %> + <% if CurrentUser.has_saved_searches? %> + + Saved Searches + + <% SavedSearch.categories_for(CurrentUser.user).each do |category| %> +

<%= link_to category, posts_path(tags: "search:#{category}") %>

+ <% end %> + + + <% end %> + API Key