logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

statuses_index.rb (1864B)


  1. # frozen_string_literal: true
  2. class StatusesIndex < Chewy::Index
  3. settings index: { refresh_interval: '15m' }, 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. content: {
  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. },
  31. }
  32. define_type ::Status.without_reblogs do
  33. crutch :mentions do |collection|
  34. data = ::Mention.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id)
  35. data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
  36. end
  37. crutch :favourites do |collection|
  38. data = ::Favourite.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id)
  39. data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
  40. end
  41. crutch :reblogs do |collection|
  42. data = ::Status.where(reblog_of_id: collection.map(&:id)).pluck(:reblog_of_id, :account_id)
  43. data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
  44. end
  45. root date_detection: false do
  46. field :account_id, type: 'long'
  47. field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].join("\n\n") } do
  48. field :stemmed, type: 'text', analyzer: 'content'
  49. end
  50. field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
  51. field :created_at, type: 'date'
  52. end
  53. end
  54. end