Files
fizzy/app/models/search/result.rb
T
Donal McBreen fc56ad9d7c Combine uuid-old and uuid branch changes
- Switch to binary 16 for UUID keys
- Remove AccountScopedRecord base class, all model use binary uuids now
- Fix the search sql to serialize uuids properly
- Patch the MySQL schema dumper to output binary lengths
2025-11-17 09:12:34 -05:00

39 lines
902 B
Ruby

class Search::Result < ApplicationRecord
attribute :card_id, :uuid
attribute :comment_id, :uuid
belongs_to :creator, class_name: "User"
belongs_to :card, foreign_key: :card_id, optional: true
belongs_to :comment, foreign_key: :comment_id, optional: true
def card_title
highlight(card.title, show: :full) if card_id
end
def card_description
highlight(card.description.to_plain_text, show: :snippet) if card_id
end
def comment_body
highlight(comment.body.to_plain_text, show: :snippet) if comment_id
end
def source
comment_id.present? ? comment : card
end
def readonly?
true
end
private
def highlight(text, show:)
if text.present? && attribute?(:query)
highlighter = Search::Highlighter.new(query)
show == :snippet ? highlighter.snippet(text) : highlighter.highlight(text)
else
text
end
end
end