1
0

accounts_index.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: 'uax_url_email',
  21. filter: %w(
  22. english_possessive_stemmer
  23. lowercase
  24. asciifolding
  25. cjk_width
  26. english_stop
  27. english_stemmer
  28. ),
  29. },
  30. verbatim: {
  31. tokenizer: 'standard',
  32. filter: %w(lowercase asciifolding cjk_width),
  33. },
  34. edge_ngram: {
  35. tokenizer: 'edge_ngram',
  36. filter: %w(lowercase asciifolding cjk_width),
  37. },
  38. },
  39. tokenizer: {
  40. edge_ngram: {
  41. type: 'edge_ngram',
  42. min_gram: 1,
  43. max_gram: 15,
  44. },
  45. },
  46. }
  47. index_scope ::Account.searchable.includes(:account_stat)
  48. root date_detection: false do
  49. field(:id, type: 'long')
  50. field(:following_count, type: 'long')
  51. field(:followers_count, type: 'long')
  52. field(:properties, type: 'keyword', value: ->(account) { account.searchable_properties })
  53. field(:last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at })
  54. field(:display_name, type: 'text', analyzer: 'verbatim') { field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'verbatim' }
  55. 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' }
  56. field(:text, type: 'text', value: ->(account) { account.searchable_text }) { field :stemmed, type: 'text', analyzer: 'natural' }
  57. end
  58. end