Skip to content

Commit c73f13d

Browse files
committed
Set post as searchable
1 parent 67742ab commit c73f13d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/models/better_together/post.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ class Post < ApplicationRecord
2121
categorizable
2222

2323
translates :title
24+
alias name title
2425
translates :content, backend: :action_text
2526

27+
settings index: default_elasticsearch_index
28+
2629
slugged :title
2730

2831
validates :title,
@@ -40,6 +43,16 @@ def to_s
4043

4144
configure_attachment_cleanup
4245

46+
# Customize the data sent to Elasticsearch for indexing
47+
def as_indexed_json(_options = {})
48+
as_json(
49+
only: [:id],
50+
methods: [:title, :name, :slug, *self.class.localized_attribute_list.keep_if do |a|
51+
a.starts_with?('title' || a.starts_with?('slug') || a.starts_with?('content'))
52+
end]
53+
)
54+
end
55+
4356
private
4457

4558
def add_creator_as_author

0 commit comments

Comments
 (0)