The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

44 lignes
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. define_type ::Account.searchable.includes(:account_stat), delete_if: ->(account) { account.destroyed? || !account.searchable? } do
  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
  36. end