2018-02-10 07:04:47 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesIndex < Chewy::Index
|
2022-03-28 08:17:17 +09:00
|
|
|
include FormattingHelper
|
|
|
|
|
2018-02-10 07:04:47 +09:00
|
|
|
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-31 07:49:24 +09:00
|
|
|
field :text, type: 'text', value: ->(status) { status.searchable_text } 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
|