fedibird-fe/app/chewy/accounts_index.rb

168 lines
4.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class AccountsIndex < Chewy::Index
2023-01-27 00:04:57 +00:00
settings index: { refresh_interval: '5m' }, 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',
},
},
tokenizer: {
edge_ngram: {
type: 'edge_ngram',
min_gram: 1,
max_gram: 15,
},
kuromoji_user_dict: {
type: 'kuromoji_tokenizer',
user_dictionary: 'userdic.txt',
},
nori_user_dict: {
type: 'nori_tokenizer',
decompound_mode: 'mixed',
},
},
analyzer: {
2023-01-27 00:04:57 +00:00
title: {
tokenizer: 'whitespace',
filter: %w(lowercase asciifolding cjk_width),
},
2023-01-27 00:04:57 +00:00
ja_title: {
type: 'custom',
char_filter: %w(
icu_normalizer
kuromoji_iteration_mark
),
tokenizer: 'kuromoji_user_dict',
filter: %w(lowercase asciifolding cjk_width),
},
2020-08-15 13:25:38 +00:00
2023-01-27 00:04:57 +00:00
ko_title: {
tokenizer: 'nori_user_dict',
filter: %w(lowercase asciifolding cjk_width),
},
zh_title: {
tokenizer: 'ik_max_word',
filter: %w(lowercase asciifolding cjk_width),
},
content: {
tokenizer: 'uax_url_email',
2020-08-15 13:25:38 +00:00
filter: %w(
2023-01-27 00:04:57 +00:00
english_possessive_stemmer
2020-08-15 13:25:38 +00:00
lowercase
2023-01-27 00:04:57 +00:00
asciifolding
2020-08-15 13:25:38 +00:00
cjk_width
2023-01-27 00:04:57 +00:00
english_stop
english_stemmer
2020-08-15 13:25:38 +00:00
),
},
2023-01-27 00:04:57 +00:00
ja_content: {
2020-08-15 13:25:38 +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
),
2020-08-15 13:25:38 +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
),
},
2023-01-27 00:04:57 +00:00
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
},
2023-01-27 00:04:57 +00:00
edge_ngram: {
tokenizer: 'edge_ngram',
filter: %w(lowercase asciifolding cjk_width),
2020-08-15 13:25:38 +00:00
},
},
}
2021-07-12 07:39:07 +00:00
index_scope ::Account.searchable.includes(:account_stat), delete_if: ->(account) { account.destroyed? || !account.searchable? }
2021-07-12 07:39:07 +00:00
root date_detection: false do
field :id, type: 'long'
2023-01-27 00:04:57 +00:00
field :display_name, type: 'text', analyzer: 'title' do
field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'title'
field :ja_stemmed, type: 'text', analyzer: 'ja_title', search_analyzer: 'title'
field :ko_stemmed, type: 'text', analyzer: 'ko_title', search_analyzer: 'title'
field :zh_stemmed, type: 'text', analyzer: 'zh_title', search_analyzer: 'title'
2021-07-12 07:39:07 +00:00
end
2020-07-14 10:03:54 +00:00
2023-01-27 00:04:57 +00:00
field :acct, type: 'text', analyzer: 'title', value: ->(account) { [account.username, account.domain].compact.join('@') } do
field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'title'
2021-07-12 07:39:07 +00:00
end
2020-08-15 13:25:38 +00:00
2021-07-12 07:39:07 +00:00
field :actor_type, type: 'keyword', normalizer: 'keyword'
2021-07-12 07:39:07 +00:00
field :text, type: 'text', value: ->(account) { account.index_text } do
2023-01-27 00:04:57 +00:00
field :en_stemmed, type: 'text', analyzer: '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'
end
2021-07-12 07:39:07 +00:00
field :discoverable, type: 'boolean'
field :following_count, type: 'long', value: ->(account) { account.following.local.count }
field :followers_count, type: 'long', value: ->(account) { account.followers.local.count }
field :subscribing_count, type: 'long', value: ->(account) { account.subscribing.local.count }
field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at }
end
end