闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

  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.unscoped.without_reblogs.includes(:media_attachments) 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 :id, type: 'long'
  47. field :account_id, type: 'long'
  48. field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do
  49. field :stemmed, type: 'text', analyzer: 'content'
  50. end
  51. field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
  52. end
  53. end
  54. end