Skip to content

Commit

Permalink
Merge pull request #107 from solver-it-sro/note-indexing
Browse files Browse the repository at this point in the history
GO-279 Index message thread note in own column
  • Loading branch information
mirrec authored Oct 16, 2023
2 parents 230443f + afa9143 commit a11fc72
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions app/lib/event_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def self.reset!
EventBus.subscribe :message_thread_changed, ->(message_thread) {
Searchable::ReindexMessageThreadJob.perform_later(message_thread.id)
}

EventBus.subscribe :message_thread_note_created, ->(note) {
Searchable::ReindexMessageThreadJob.perform_later(note.message_thread_id)
}
EventBus.subscribe :message_thread_note_changed, ->(note) {
Searchable::ReindexMessageThreadJob.perform_later(note.message_thread_id)
}

EventBus.subscribe :message_thread_tag_changed,
->(message_thread_tag) { Searchable::ReindexMessageThreadJob.perform_later(message_thread_tag.message_thread_id) }
EventBus.subscribe :tag_renamed, ->(tag) { Searchable::ReindexMessageThreadsWithTagIdJob.perform_later(tag.id) }
Expand Down
3 changes: 3 additions & 0 deletions app/models/message_thread_note.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class MessageThreadNote < ApplicationRecord
belongs_to :message_thread

after_create_commit ->(note) { EventBus.publish(:message_thread_note_created, note) }
after_update_commit ->(note) { EventBus.publish(:message_thread_note_changed, note) }
end
1 change: 1 addition & 0 deletions app/models/searchable/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Searchable::Indexer
def self.index_message_thread(message_thread)
record = ::Searchable::MessageThread.find_or_initialize_by(message_thread_id: message_thread.id)
record.title = Searchable::IndexHelpers.searchable_string(message_thread.title)
record.note = Searchable::IndexHelpers.searchable_string(message_thread.message_thread_note&.note.to_s)
record.tag_ids = message_thread.tags.map(&:id)
record.tag_names = Searchable::IndexHelpers.searchable_string(message_thread.tags.map(&:name).join(' ').gsub(/[:\/]/, " "))
record.content = message_thread.messages.map { |message| message_to_searchable_string(message) }.join(' ')
Expand Down
2 changes: 1 addition & 1 deletion app/models/searchable/message_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Searchable::MessageThread < ApplicationRecord

include PgSearch::Model
pg_search_scope :pg_search_all,
against: [:title, :content, :tag_names],
against: [:title, :content, :note, :tag_names],
using: {
tsearch: {
highlight: {
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20231016140436_add_note_to_searchable_message_thread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddNoteToSearchableMessageThread < ActiveRecord::Migration[7.0]
def change
add_column :searchable_message_threads, :note, :string

Searchable::MessageThread.reset_column_information

Searchable::MessageThread.update_all(note: "")

change_column_null :searchable_message_threads, :note, false
end
end
9 changes: 2 additions & 7 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a11fc72

Please sign in to comment.