search_concern.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. module Status::SearchConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. scope :indexable, -> { without_reblogs.where(visibility: :public).joins(:account).where(account: { indexable: true }) }
  6. end
  7. def searchable_by
  8. @searchable_by ||= begin
  9. ids = []
  10. ids << account_id if local?
  11. ids += local_mentioned.pluck(:id)
  12. ids += local_favorited.pluck(:id)
  13. ids += local_reblogged.pluck(:id)
  14. ids += local_bookmarked.pluck(:id)
  15. ids += preloadable_poll.local_voters.pluck(:id) if preloadable_poll.present?
  16. ids.uniq
  17. end
  18. end
  19. def searchable_text
  20. [
  21. spoiler_text,
  22. FormattingHelper.extract_status_plain_text(self),
  23. preloadable_poll&.options&.join("\n\n"),
  24. ordered_media_attachments.map(&:description).join("\n\n"),
  25. ].compact.join("\n\n")
  26. end
  27. def searchable_properties
  28. [].tap do |properties|
  29. properties << 'image' if ordered_media_attachments.any?(&:image?)
  30. properties << 'video' if ordered_media_attachments.any?(&:video?)
  31. properties << 'audio' if ordered_media_attachments.any?(&:audio?)
  32. properties << 'media' if with_media?
  33. properties << 'poll' if with_poll?
  34. properties << 'link' if with_preview_card?
  35. properties << 'embed' if preview_card&.video?
  36. properties << 'sensitive' if sensitive?
  37. properties << 'reply' if reply?
  38. end
  39. end
  40. end