statuses_index.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. class StatusesIndex < 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.kept.without_reblogs.includes(:media_attachments, :local_mentioned, :local_favorited, :local_reblogged, :local_bookmarked, :tags, preview_cards_status: :preview_card, preloadable_poll: :local_voters), delete_if: ->(status) { status.searchable_by.empty? }
  48. root date_detection: false do
  49. field(:id, type: 'long')
  50. field(:account_id, type: 'long')
  51. field(:text, type: 'text', analyzer: 'verbatim', value: ->(status) { status.searchable_text }) { field(:stemmed, type: 'text', analyzer: 'content') }
  52. field(:tags, type: 'text', analyzer: 'hashtag', value: ->(status) { status.tags.map(&:display_name) })
  53. field(:searchable_by, type: 'long', value: ->(status) { status.searchable_by })
  54. field(:language, type: 'keyword')
  55. field(:properties, type: 'keyword', value: ->(status) { status.searchable_properties })
  56. field(:created_at, type: 'date', value: ->(status) { clamp_date(status.created_at) })
  57. end
  58. end