public_statuses_index.rb 1.7 KB

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