Add status_references to full-text search target

This commit is contained in:
KMY 2023-08-25 17:51:49 +09:00
parent bde0ddaca6
commit 3a5b8819d6
3 changed files with 13 additions and 0 deletions

View file

@ -53,6 +53,11 @@ class StatusesIndex < Chewy::Index
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
end 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| crutch :reblogs do |collection|
data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id) 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) } 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(:searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) })
field(:searchability, type: 'keyword', value: ->(status) { status.compute_searchability }) field(:searchability, type: 'keyword', value: ->(status) { status.compute_searchability })
field(:language, type: 'keyword') field(:language, type: 'keyword')
field(:domain, type: 'keyword', value: ->(status) { status.account.domain || '' })
field(:properties, type: 'keyword', value: ->(status) { status.searchable_properties }) field(:properties, type: 'keyword', value: ->(status) { status.searchable_properties })
field(:created_at, type: 'date') field(:created_at, type: 'date')
end end

View file

@ -16,6 +16,7 @@ module StatusSearchConcern
ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id) ids += mentions.joins(:account).merge(Account.local).active.pluck(:account_id)
ids += favourites.joins(:account).merge(Account.local).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 += 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 += reblogs.joins(:account).merge(Account.local).pluck(:account_id)
ids += bookmarks.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? 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.mentions[id] || []
ids += preloaded.favourites[id] || [] ids += preloaded.favourites[id] || []
ids += preloaded.emoji_reactions[id] || [] ids += preloaded.emoji_reactions[id] || []
ids += preloaded.status_references[id] || []
ids += preloaded.reblogs[id] || [] ids += preloaded.reblogs[id] || []
ids += preloaded.bookmarks[id] || [] ids += preloaded.bookmarks[id] || []
ids += preloaded.votes[id] || [] ids += preloaded.votes[id] || []
@ -51,6 +53,7 @@ module StatusSearchConcern
properties << 'embed' if preview_cards.any?(&:video?) properties << 'embed' if preview_cards.any?(&:video?)
properties << 'sensitive' if sensitive? properties << 'sensitive' if sensitive?
properties << 'reply' if reply? properties << 'reply' if reply?
properties << 'reference' if with_status_reference?
end end
end end
end end

View file

@ -268,6 +268,10 @@ class Status < ApplicationRecord
preloadable_poll.present? preloadable_poll.present?
end end
def with_status_reference?
reference_objects.any?
end
def non_sensitive_with_media? def non_sensitive_with_media?
!sensitive? && with_media? !sensitive? && with_media?
end end