You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

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