statuses_index.rb 2.17 KB
Newer Older
1
2
3
4
# frozen_string_literal: true

class StatusesIndex < Chewy::Index
  settings index: { refresh_interval: '15m' }, analysis: {
5
6
7
8
9
10
11
12
13
14
15
16
    filter: {
      english_stop: {
        type: 'stop',
        stopwords: '_english_',
      },
      english_stemmer: {
        type: 'stemmer',
        language: 'english',
      },
      english_possessive_stemmer: {
        type: 'stemmer',
        language: 'possessive_english',
17
18
19
20
      },
    },
    analyzer: {
      content: {
21
        tokenizer: 'uax_url_email',
22
        filter: %w(
23
          english_possessive_stemmer
24
          lowercase
25
          asciifolding
26
          cjk_width
27
28
          english_stop
          english_stemmer
29
        ),
30
31
      },
    },
32
33
  }

34
  define_type ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) do
35
    crutch :mentions do |collection|
36
      data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local, silent: false).pluck(:status_id, :account_id)
37
38
39
40
      data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
    end

    crutch :favourites do |collection|
41
      data = ::Favourite.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
42
43
44
45
      data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
    end

    crutch :reblogs do |collection|
46
      data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id)
47
48
49
      data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
    end

50
51
52
53
54
    crutch :bookmarks do |collection|
      data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
      data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
    end

55
    root date_detection: false do
56
      field :id, type: 'long'
57
58
      field :account_id, type: 'long'

Takeshi Umeda's avatar
Takeshi Umeda committed
59
      field :text, type: 'text', value: ->(status) { status.index_text } do
60
61
62
63
64
65
66
        field :stemmed, type: 'text', analyzer: 'content'
      end

      field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
    end
  end
end