23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/models/iron/entry/searchable.rb', line 23
def reindex
searchable_definitions = collect_searchable_definitions
if searchable_definitions.empty?
search_records.destroy_all
return
end
active_locale_ids = fields.map(&:locale_id).uniq
Locale.where(id: active_locale_ids).find_each do |locale|
title_text = title_field_for(locale)&.value
content_text = assemble_search_content(searchable_definitions, locale)
if title_text.present? || content_text.present?
SearchRecord.upsert!(
entry_id: id,
locale_id: locale.id,
title: title_text,
content: content_text,
created_at: created_at || Time.current
)
else
search_records.where(locale:).destroy_all
end
end
search_records.where.not(locale_id: active_locale_ids).destroy_all
end
|