Files
danbooru/app/presenters/post_set_presenters/post.rb
evazion f38c38f26e search: split tag_match into user_tag_match / system_tag_match.
When doing a tag search, we have to be careful about which user we're
running the search as because the results depend on the current user.
Specifically, things like private favorites, private favorite groups,
post votes, saved searches, and flagger names depend on the user's
permissions, and whether non-safe or deleted posts are filtered out
depend on whether the user has safe mode on or the hide deleted posts
setting enabled.

* Refactor internal searches to explicitly state whether they're
  running as the system user (DanbooruBot) or as the current user.
* Explicitly pass in the current user to PostQueryBuilder instead of
  implicitly relying on the CurrentUser global.
* Get rid of CurrentUser.admin_mode? (used to ignore the hide deleted
  post setting) and CurrentUser.without_safe_mode (used to ignore safe
  mode).
* Change the /counts/posts.json endpoint to ignore safe mode and the
  hide deleted posts settings when counting posts.
* Fix searches not correctly overriding the hide deleted posts setting
  when multiple status: metatags were used (e.g. `status:banned status:active`)
* Fix fast_count not respecting the hide deleted posts setting when the
  status:banned metatag was used.
2020-05-07 03:29:44 -05:00

63 lines
1.5 KiB
Ruby

module PostSetPresenters
class Post < Base
MAX_TAGS = 25
attr_accessor :post_set
delegate :posts, :to => :post_set
def initialize(post_set)
@post_set = post_set
end
def tag_set_presenter
@tag_set_presenter ||= TagSetPresenter.new(related_tags.take(MAX_TAGS))
end
def post_previews_html(template, options = {})
super(template, options.merge(show_cropped: true))
end
def related_tags
if post_set.query.is_wildcard_search?
wildcard_tags
elsif post_set.query.is_metatag?(:search)
saved_search_tags
elsif post_set.query.is_empty_search? || post_set.query.is_metatag?(:order, :rank)
popular_tags
elsif post_set.query.is_single_term?
similar_tags
else
frequent_tags
end
end
def popular_tags
if PopularSearchService.enabled?
PopularSearchService.new(Date.today).tags
else
frequent_tags
end
end
def similar_tags
RelatedTagCalculator.cached_similar_tags_for_search(post_set.tag_string, MAX_TAGS, CurrentUser.user)
end
def frequent_tags
RelatedTagCalculator.frequent_tags_for_post_array(post_set.posts).take(MAX_TAGS)
end
def wildcard_tags
Tag.wildcard_matches(post_set.tag_string)
end
def saved_search_tags
["search:all"] + SavedSearch.labels_for(CurrentUser.user.id).map {|x| "search:#{x}"}
end
def tag_list_html(**options)
tag_set_presenter.tag_list_html(name_only: post_set.query.is_metatag?(:search), **options)
end
end
end