1
0

accounts_index.rb 2.0 KB

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