Add account note to search index

This commit is contained in:
noellabo 2020-08-15 22:25:38 +09:00
parent c985cf5536
commit 176dd499b7
3 changed files with 41 additions and 0 deletions

View file

@ -12,6 +12,19 @@ class AccountsIndex < Chewy::Index
tokenizer: 'edge_ngram', tokenizer: 'edge_ngram',
filter: %w(lowercase asciifolding cjk_width), filter: %w(lowercase asciifolding cjk_width),
}, },
sudachi_content: {
filter: %w(
lowercase
cjk_width
sudachi_part_of_speech
sudachi_ja_stop
sudachi_baseform
search
),
tokenizer: 'sudachi_tokenizer',
type: 'custom',
},
}, },
tokenizer: { tokenizer: {
@ -20,6 +33,19 @@ class AccountsIndex < Chewy::Index
min_gram: 1, min_gram: 1,
max_gram: 15, max_gram: 15,
}, },
sudachi_tokenizer: {
type: 'sudachi_tokenizer',
discard_punctuation: true,
resources_path: '/etc/elasticsearch',
settings_path: '/etc/elasticsearch/sudachi.json',
},
},
filter: {
search: {
type: 'sudachi_split',
mode: 'search',
},
}, },
} }
@ -37,6 +63,10 @@ class AccountsIndex < Chewy::Index
field :actor_type, type: 'keyword', analyzer: 'content' field :actor_type, type: 'keyword', analyzer: 'content'
field :text, type: 'text', value: ->(account) { account.index_text } do
field :stemmed, type: 'text', analyzer: 'sudachi_content'
end
field :following_count, type: 'long', value: ->(account) { account.following.local.count } field :following_count, type: 'long', value: ->(account) { account.following.local.count }
field :followers_count, type: 'long', value: ->(account) { account.followers.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 :subscribing_count, type: 'long', value: ->(account) { account.subscribing.local.count }

View file

@ -22,11 +22,18 @@ class StatusesIndex < Chewy::Index
sudachi_part_of_speech sudachi_part_of_speech
sudachi_ja_stop sudachi_ja_stop
sudachi_baseform sudachi_baseform
search
), ),
tokenizer: 'sudachi_tokenizer', tokenizer: 'sudachi_tokenizer',
type: 'custom', type: 'custom',
}, },
}, },
filter: {
search: {
type: 'sudachi_split',
mode: 'search',
},
},
} }
define_type ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) do define_type ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) do

View file

@ -392,6 +392,10 @@ class Account < ApplicationRecord
end.permitted_for(self, account) end.permitted_for(self, account)
end end
def index_text
ActionController::Base.helpers.strip_tags(note)
end
class Field < ActiveModelSerializers::Model class Field < ActiveModelSerializers::Model
attributes :name, :value, :verified_at, :account attributes :name, :value, :verified_at, :account