The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

37 linhas
1.3 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: 'edge_ngram', search_analyzer: 'content'
  26. field :acct, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content', value: ->(account) { [account.username, account.domain].compact.join('@') }
  27. field :following_count, type: 'long', value: ->(account) { account.active_relationships.count }
  28. field :followers_count, type: 'long', value: ->(account) { account.passive_relationships.count }
  29. field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at }
  30. end
  31. end
  32. end