2018-02-09 14:04:47 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesIndex < Chewy::Index
|
2022-03-27 16:17:17 -07:00
|
|
|
include FormattingHelper
|
|
|
|
|
2018-02-09 14:04:47 -08: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-18 13:02:08 -08:00
|
|
|
index_scope ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll)
|
2018-02-09 14:04:47 -08:00
|
|
|
|
2021-11-18 13:02:08 -08: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-09 14:04:47 -08:00
|
|
|
|
2021-11-18 13:02:08 -08: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-09 14:04:47 -08:00
|
|
|
|
2021-11-18 13:02:08 -08: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-21 18:40:03 -07:00
|
|
|
|
2021-11-18 13:02:08 -08: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-09 14:04:47 -08:00
|
|
|
|
2021-11-18 13:02:08 -08:00
|
|
|
root date_detection: false do
|
|
|
|
field :id, type: 'long'
|
|
|
|
field :account_id, type: 'long'
|
2018-02-09 14:04:47 -08:00
|
|
|
|
2022-03-30 15:49:24 -07:00
|
|
|
field :text, type: 'text', value: ->(status) { status.searchable_text } do
|
2021-11-18 13:02:08 -08:00
|
|
|
field :stemmed, type: 'text', analyzer: 'content'
|
2018-02-09 14:04:47 -08:00
|
|
|
end
|
2021-11-18 13:02:08 -08:00
|
|
|
|
|
|
|
field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
|
2018-02-09 14:04:47 -08:00
|
|
|
end
|
|
|
|
end
|