Files
fizzy/app/models/card/searchable.rb
T
2025-07-24 16:47:57 +02:00

38 lines
1.0 KiB
Ruby

module Card::Searchable
extend ActiveSupport::Concern
included do
include ::Searchable
searchable_by :title, :description, using: :cards_search_index
scope :mentioning, ->(query) do
cards = Card.search(query).select(:id).to_sql
comments = Comment.search(query).select(:id).to_sql
left_joins(:comments).where("cards.id in (#{cards}) or comments.id in (#{comments})").distinct
end
scope :similar_to, ->(query) do
cards = Card.search_similar(query).select(:id).to_sql
comments = Comment.search_similar(query).select(:id).to_sql
left_joins(:comments).where("cards.id in (#{cards}) or comments.id in (#{comments})").distinct
end
end
def search_embedding_content
<<~CONTENT
Title: #{title}
Description: #{description.to_plain_text}
Created by: #{creator.name}}
CONTENT
end
private
# TODO: Temporary until we stabilize the search API
def title_and_description
[ title, description.to_plain_text ].join(" ")
end
end