accounts_index.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. class AccountsIndex < Chewy::Index
  3. settings index: index_preset(refresh_interval: '30s'), analysis: {
  4. filter: {
  5. english_stop: {
  6. type: 'stop',
  7. stopwords: '_english_',
  8. },
  9. english_stemmer: {
  10. type: 'stemmer',
  11. language: 'english',
  12. },
  13. english_possessive_stemmer: {
  14. type: 'stemmer',
  15. language: 'possessive_english',
  16. },
  17. },
  18. analyzer: {
  19. natural: {
  20. tokenizer: 'standard',
  21. filter: %w(
  22. lowercase
  23. asciifolding
  24. cjk_width
  25. elision
  26. english_possessive_stemmer
  27. english_stop
  28. english_stemmer
  29. ),
  30. },
  31. verbatim: {
  32. tokenizer: 'standard',
  33. filter: %w(lowercase asciifolding cjk_width),
  34. },
  35. edge_ngram: {
  36. tokenizer: 'edge_ngram',
  37. filter: %w(lowercase asciifolding cjk_width),
  38. },
  39. },
  40. tokenizer: {
  41. edge_ngram: {
  42. type: 'edge_ngram',
  43. min_gram: 1,
  44. max_gram: 15,
  45. },
  46. },
  47. }
  48. index_scope ::Account.searchable.includes(:account_stat)
  49. root date_detection: false do
  50. field(:id, type: 'long')
  51. field(:following_count, type: 'long')
  52. field(:followers_count, type: 'long')
  53. field(:properties, type: 'keyword', value: ->(account) { account.searchable_properties })
  54. field(:last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at })
  55. field(:display_name, type: 'text', analyzer: 'verbatim') { field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'verbatim' }
  56. field(:username, type: 'text', analyzer: 'verbatim', value: ->(account) { [account.username, account.domain].compact.join('@') }) { field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'verbatim' }
  57. field(:text, type: 'text', analyzer: 'verbatim', value: ->(account) { account.searchable_text }) { field :stemmed, type: 'text', analyzer: 'natural' }
  58. end
  59. end