2018-02-09 22:04:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesIndex < Chewy::Index
|
2023-01-27 00:04:57 +00: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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
char_filter: {
|
|
|
|
tsconvert: {
|
|
|
|
type: 'stconvert',
|
|
|
|
keep_both: false,
|
|
|
|
delimiter: '#',
|
|
|
|
convert_type: 't2s',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-06-27 20:50:16 +00:00
|
|
|
tokenizer: {
|
2023-01-27 00:04:57 +00:00
|
|
|
kuromoji_user_dict: {
|
|
|
|
type: 'kuromoji_tokenizer',
|
|
|
|
user_dictionary: 'userdic.txt',
|
|
|
|
},
|
|
|
|
|
|
|
|
nori_user_dict: {
|
|
|
|
type: 'nori_tokenizer',
|
|
|
|
decompound_mode: 'mixed',
|
2018-02-09 22:04:47 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-27 00:04:57 +00:00
|
|
|
|
2018-02-09 22:04:47 +00:00
|
|
|
analyzer: {
|
2023-01-27 00:04:57 +00:00
|
|
|
en_content: {
|
|
|
|
tokenizer: 'uax_url_email',
|
2018-02-09 22:04:47 +00:00
|
|
|
filter: %w(
|
2023-01-27 00:04:57 +00:00
|
|
|
english_possessive_stemmer
|
2018-02-09 22:04:47 +00:00
|
|
|
lowercase
|
2023-01-27 00:04:57 +00:00
|
|
|
asciifolding
|
2018-02-09 22:04:47 +00:00
|
|
|
cjk_width
|
2023-01-27 00:04:57 +00:00
|
|
|
english_stop
|
|
|
|
english_stemmer
|
2018-02-09 22:04:47 +00:00
|
|
|
),
|
2023-01-27 00:04:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ja_content: {
|
2019-06-27 20:50:16 +00:00
|
|
|
type: 'custom',
|
2023-01-27 00:04:57 +00:00
|
|
|
char_filter: %w(
|
|
|
|
icu_normalizer
|
|
|
|
kuromoji_iteration_mark
|
|
|
|
),
|
|
|
|
tokenizer: 'kuromoji_user_dict',
|
|
|
|
filter: %w(
|
|
|
|
kuromoji_baseform
|
|
|
|
kuromoji_part_of_speech
|
|
|
|
ja_stop
|
|
|
|
kuromoji_stemmer
|
|
|
|
kuromoji_number
|
|
|
|
cjk_width
|
|
|
|
lowercase
|
|
|
|
),
|
2018-02-09 22:04:47 +00:00
|
|
|
},
|
2023-01-27 00:04:57 +00:00
|
|
|
|
|
|
|
ko_content: {
|
|
|
|
tokenizer: 'nori_user_dict',
|
|
|
|
filter: %w(
|
|
|
|
english_possessive_stemmer
|
|
|
|
lowercase
|
|
|
|
asciifolding
|
|
|
|
cjk_width
|
|
|
|
english_stop
|
|
|
|
english_stemmer
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
zh_content: {
|
|
|
|
tokenizer: 'ik_max_word',
|
|
|
|
filter: %w(
|
|
|
|
english_possessive_stemmer
|
|
|
|
lowercase
|
|
|
|
asciifolding
|
|
|
|
cjk_width
|
|
|
|
english_stop
|
|
|
|
english_stemmer
|
|
|
|
),
|
|
|
|
char_filter: %w(tsconvert),
|
2020-08-15 13:25:38 +00:00
|
|
|
},
|
|
|
|
},
|
2018-02-09 22:04:47 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 07:39:07 +00:00
|
|
|
index_scope ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll)
|
2018-02-09 22:04:47 +00:00
|
|
|
|
2021-07-12 07:39:07 +00: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 22:04:47 +00:00
|
|
|
|
2021-07-12 07:39:07 +00: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 22:04:47 +00:00
|
|
|
|
2021-07-12 07:39:07 +00: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 01:40:03 +00:00
|
|
|
|
2021-07-12 07:39:07 +00: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
|
2021-05-19 05:58:27 +00:00
|
|
|
|
2023-01-27 00:04:57 +00:00
|
|
|
crutch :votes do |collection|
|
|
|
|
data = ::PollVote.joins(:poll).where(poll: { 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
|
|
|
|
|
2021-07-12 07:39:07 +00:00
|
|
|
crutch :emoji_reactions do |collection|
|
|
|
|
data = ::EmojiReaction.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 22:04:47 +00:00
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
crutch :status_references do |collection|
|
|
|
|
data = ::StatusReference.joins(:status).where(target_status_id: collection.map(&:id)).where(status: { account: Account.local }).pluck(:target_status_id, :'status.account_id')
|
|
|
|
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
|
|
|
|
end
|
|
|
|
|
2021-07-12 07:39:07 +00:00
|
|
|
root date_detection: false do
|
|
|
|
field :id, type: 'long'
|
|
|
|
field :account_id, type: 'long'
|
2023-01-27 00:04:57 +00:00
|
|
|
field :domain, type: 'keyword', value: ->(status) { status.account_domain }
|
2018-02-09 22:04:47 +00:00
|
|
|
|
2021-07-12 07:39:07 +00:00
|
|
|
field :text, type: 'text', value: ->(status) { status.index_text } do
|
2023-01-27 00:04:57 +00:00
|
|
|
field :en_stemmed, type: 'text', analyzer: 'en_content'
|
|
|
|
field :ja_stemmed, type: 'text', analyzer: 'ja_content'
|
|
|
|
field :ko_stemmed, type: 'text', analyzer: 'ko_content'
|
|
|
|
field :zh_stemmed, type: 'text', analyzer: 'zh_content'
|
2018-02-09 22:04:47 +00:00
|
|
|
end
|
2021-07-12 07:39:07 +00:00
|
|
|
|
2023-01-27 00:04:57 +00:00
|
|
|
field :mentioned_account_id, type: 'long'
|
|
|
|
field :tag_id, type: 'long'
|
|
|
|
field :media_type, type: 'keyword'
|
|
|
|
field :reference_type, type: 'keyword'
|
|
|
|
field :language, type: 'keyword'
|
|
|
|
|
|
|
|
field :replies_count, type: 'long'
|
|
|
|
field :reblogs_count, type: 'long'
|
|
|
|
field :favourites_count, type: 'long'
|
|
|
|
field :emoji_reactions_count, type: 'long'
|
|
|
|
field :status_referred_by_count, type: 'long'
|
|
|
|
|
|
|
|
field :visibility, type: 'keyword'
|
2021-07-12 07:39:07 +00:00
|
|
|
field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
|
2022-08-23 05:14:23 +00:00
|
|
|
field :searchability, type: 'keyword', value: ->(status) { status.compute_searchability }
|
2018-02-09 22:04:47 +00:00
|
|
|
end
|
|
|
|
end
|