accounts_index.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class AccountsIndex < Chewy::Index
  3. include DatetimeClampingConcern
  4. settings index: { refresh_interval: '30s' }, analysis: {
  5. analyzer: {
  6. content: {
  7. tokenizer: 'whitespace',
  8. filter: %w(lowercase asciifolding cjk_width),
  9. },
  10. edge_ngram: {
  11. tokenizer: 'edge_ngram',
  12. filter: %w(lowercase asciifolding cjk_width),
  13. },
  14. },
  15. tokenizer: {
  16. edge_ngram: {
  17. type: 'edge_ngram',
  18. min_gram: 1,
  19. max_gram: 15,
  20. },
  21. },
  22. }
  23. index_scope ::Account.searchable.includes(:account_stat)
  24. root date_detection: false do
  25. field :id, type: 'long'
  26. field :display_name, type: 'text', analyzer: 'content' do
  27. field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content'
  28. end
  29. field :acct, type: 'text', analyzer: 'content', value: ->(account) { [account.username, account.domain].compact.join('@') } do
  30. field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content'
  31. end
  32. field :following_count, type: 'long', value: ->(account) { account.following_count }
  33. field :followers_count, type: 'long', value: ->(account) { account.followers_count }
  34. field :last_status_at, type: 'date', value: ->(account) { clamp_date(account.last_status_at || account.created_at) }
  35. end
  36. end