闭社主体 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.

67 lines
2.4 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.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) do
  33. crutch :mentions do |collection|
  34. data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local, silent: false).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)).where(account: Account.local).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)).where(account: Account.local).pluck(:reblog_of_id, :account_id)
  43. data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
  44. end
  45. crutch :bookmarks do |collection|
  46. data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
  47. data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
  48. end
  49. root date_detection: false do
  50. field :id, type: 'long'
  51. field :account_id, type: 'long'
  52. 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
  53. field :stemmed, type: 'text', analyzer: 'content'
  54. field :chn , type: 'text', analyzer: 'ik_max_word', search_analyzer: 'ik_smart'
  55. end
  56. field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
  57. end
  58. end
  59. end