diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index f84a0c69ec..35ced1d9af 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -53,6 +53,11 @@ class StatusesIndex < Chewy::Index data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } end + crutch :status_references do |collection| + data = ::StatusReference.joins(:status).where(target_status_id: collection.map(&:id), status: { account: Account.local }).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end + crutch :reblogs do |collection| data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id) data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } @@ -75,6 +80,7 @@ class StatusesIndex < Chewy::Index field(:searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }) field(:searchability, type: 'keyword', value: ->(status) { status.compute_searchability }) field(:language, type: 'keyword') + field(:domain, type: 'keyword', value: ->(status) { status.account.domain || '' }) field(:properties, type: 'keyword', value: ->(status) { status.searchable_properties }) field(:created_at, type: 'date') end diff --git a/app/models/concerns/status_search_concern.rb b/app/models/concerns/status_search_concern.rb index daf5c0a80f..ddb69126b2 100644 --- a/app/models/concerns/status_search_concern.rb +++ b/app/models/concerns/status_search_concern.rb @@ -16,6 +16,7 @@ module StatusSearchConcern ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id) ids += favourites.joins(:account).merge(Account.local).pluck(:account_id) ids += emoji_reactions.joins(:account).merge(Account.local).pluck(:account_id) + ids += references.joins(:account).merge(Account.local).pluck(:account_id) ids += reblogs.joins(:account).merge(Account.local).pluck(:account_id) ids += bookmarks.joins(:account).merge(Account.local).pluck(:account_id) ids += poll.votes.joins(:account).merge(Account.local).pluck(:account_id) if poll.present? @@ -23,6 +24,7 @@ module StatusSearchConcern ids += preloaded.mentions[id] || [] ids += preloaded.favourites[id] || [] ids += preloaded.emoji_reactions[id] || [] + ids += preloaded.status_references[id] || [] ids += preloaded.reblogs[id] || [] ids += preloaded.bookmarks[id] || [] ids += preloaded.votes[id] || [] @@ -51,6 +53,7 @@ module StatusSearchConcern properties << 'embed' if preview_cards.any?(&:video?) properties << 'sensitive' if sensitive? properties << 'reply' if reply? + properties << 'reference' if with_status_reference? end end end diff --git a/app/models/status.rb b/app/models/status.rb index 49a1a3ca3c..0aaea6ec38 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -268,6 +268,10 @@ class Status < ApplicationRecord preloadable_poll.present? end + def with_status_reference? + reference_objects.any? + end + def non_sensitive_with_media? !sensitive? && with_media? end