2019-08-18 01:45:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TagsIndex < Chewy::Index
|
2023-08-14 15:46:16 +00:00
|
|
|
settings index: index_preset(refresh_interval: '30s'), analysis: {
|
2019-08-18 01:45:51 +00:00
|
|
|
analyzer: {
|
|
|
|
content: {
|
|
|
|
tokenizer: 'keyword',
|
2023-09-04 08:18:45 +00:00
|
|
|
filter: %w(
|
|
|
|
word_delimiter_graph
|
|
|
|
lowercase
|
|
|
|
asciifolding
|
|
|
|
cjk_width
|
|
|
|
),
|
2019-08-18 01:45:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
edge_ngram: {
|
|
|
|
tokenizer: 'edge_ngram',
|
2023-09-04 08:18:45 +00:00
|
|
|
filter: %w(
|
|
|
|
lowercase
|
|
|
|
asciifolding
|
|
|
|
cjk_width
|
|
|
|
),
|
2019-08-18 01:45:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
tokenizer: {
|
|
|
|
edge_ngram: {
|
|
|
|
type: 'edge_ngram',
|
|
|
|
min_gram: 2,
|
|
|
|
max_gram: 15,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-22 20:16:43 +00:00
|
|
|
index_scope ::Tag.listable
|
|
|
|
|
|
|
|
crutch :time_period do
|
|
|
|
7.days.ago.to_date..0.days.ago.to_date
|
|
|
|
end
|
2019-08-18 01:45:51 +00:00
|
|
|
|
2021-11-18 21:02:08 +00:00
|
|
|
root date_detection: false do
|
2023-09-04 08:18:45 +00:00
|
|
|
field(:name, type: 'text', analyzer: 'content', value: :display_name) { field(:edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content') }
|
|
|
|
field(:reviewed, type: 'boolean', value: ->(tag) { tag.reviewed? })
|
|
|
|
field(:usage, type: 'long', value: ->(tag, crutches) { tag.history.aggregate(crutches.time_period).accounts })
|
|
|
|
field(:last_status_at, type: 'date', value: ->(tag) { tag.last_status_at || tag.created_at })
|
2019-08-18 01:45:51 +00:00
|
|
|
end
|
|
|
|
end
|