public_statuses_index.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. class PublicStatusesIndex < Chewy::Index
  3. include DatetimeClampingConcern
  4. settings index: index_preset(refresh_interval: '30s', number_of_shards: 5), 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. verbatim: {
  21. tokenizer: 'uax_url_email',
  22. filter: %w(lowercase),
  23. },
  24. content: {
  25. tokenizer: 'standard',
  26. filter: %w(
  27. lowercase
  28. asciifolding
  29. cjk_width
  30. elision
  31. english_possessive_stemmer
  32. english_stop
  33. english_stemmer
  34. ),
  35. },
  36. hashtag: {
  37. tokenizer: 'keyword',
  38. filter: %w(
  39. word_delimiter_graph
  40. lowercase
  41. asciifolding
  42. cjk_width
  43. ),
  44. },
  45. },
  46. }
  47. index_scope ::Status.unscoped
  48. .kept
  49. .indexable
  50. .includes(:media_attachments, :preloadable_poll, :tags, preview_cards_status: :preview_card)
  51. root date_detection: false do
  52. field(:id, type: 'long')
  53. field(:account_id, type: 'long')
  54. field(:text, type: 'text', analyzer: 'verbatim', value: ->(status) { status.searchable_text }) { field(:stemmed, type: 'text', analyzer: 'content') }
  55. field(:tags, type: 'text', analyzer: 'hashtag', value: ->(status) { status.tags.map(&:display_name) })
  56. field(:language, type: 'keyword')
  57. field(:properties, type: 'keyword', value: ->(status) { status.searchable_properties })
  58. field(:created_at, type: 'date', value: ->(status) { clamp_date(status.created_at) })
  59. end
  60. end