2018-02-10 07:04:47 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesIndex < Chewy::Index
|
|
|
|
settings index: { refresh_interval: '15m' }, analysis: {
|
|
|
|
filter: {
|
|
|
|
english_stop: {
|
|
|
|
type: 'stop',
|
|
|
|
stopwords: '_english_',
|
|
|
|
},
|
|
|
|
english_stemmer: {
|
|
|
|
type: 'stemmer',
|
|
|
|
language: 'english',
|
|
|
|
},
|
|
|
|
english_possessive_stemmer: {
|
|
|
|
type: 'stemmer',
|
|
|
|
language: 'possessive_english',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
analyzer: {
|
|
|
|
content: {
|
|
|
|
tokenizer: 'uax_url_email',
|
|
|
|
filter: %w(
|
|
|
|
english_possessive_stemmer
|
|
|
|
lowercase
|
|
|
|
asciifolding
|
|
|
|
cjk_width
|
|
|
|
english_stop
|
|
|
|
english_stemmer
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
index_scope ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll)
|
2018-02-10 07:04:47 +09:00
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
crutch :mentions do |collection|
|
|
|
|
data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local, silent: false).pluck(:status_id, :account_id)
|
|
|
|
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
|
|
|
|
end
|
2018-02-10 07:04:47 +09:00
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
crutch :favourites do |collection|
|
|
|
|
data = ::Favourite.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
|
|
|
|
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
|
|
|
|
end
|
2018-02-10 07:04:47 +09:00
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
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) }
|
|
|
|
end
|
2020-03-22 10:40:03 +09:00
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
crutch :bookmarks do |collection|
|
|
|
|
data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
|
|
|
|
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
|
|
|
|
end
|
2018-02-10 07:04:47 +09:00
|
|
|
|
2021-11-19 06:02:08 +09:00
|
|
|
root date_detection: false do
|
|
|
|
field :id, type: 'long'
|
|
|
|
field :account_id, type: 'long'
|
2018-02-10 07:04:47 +09:00
|
|
|
|
2022-03-26 10:53:34 +09:00
|
|
|
field :text, type: 'text', value: ->(status) { [status.spoiler_text, PlainTextFormatter.new(status.text, status.local?).to_s].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
|
2021-11-19 06:02:08 +09:00
|
|
|
field :stemmed, type: 'text', analyzer: 'content'
|
2018-02-10 07:04:47 +09:00
|
|
|
end
|
2021-11-19 06:02:08 +09:00
|
|
|
|
|
|
|
field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
|
2018-02-10 07:04:47 +09:00
|
|
|
end
|
|
|
|
end
|