retrospring/app/models/question.rb
Georg Gadinger 44871cbf4a add meilisearch
this thing is way too fast!  only downside is that indexing takes a bit
longer, and the search indexes are big (16Gi for 2.7 million records)

i have no idea how to properly integrate it in the UI, but it seems
promising :^)
2023-10-22 19:51:19 +02:00

43 lines
1 KiB
Ruby

class Question < ApplicationRecord
include Question::AnswerMethods
include MeiliSearch::Rails
meilisearch do
attribute :content
end
belongs_to :user, optional: true
has_many :answers, dependent: :destroy
has_many :inboxes, dependent: :destroy
validates :content, length: { minimum: 1 }
SHORT_QUESTION_MAX_LENGTH = 512
before_destroy do
rep = Report.where(target_id: self.id, type: 'Reports::Question')
rep.each do |r|
unless r.nil?
r.deleted = true
r.save
end
end
# rubocop:disable Rails/SkipsModelValidations
user&.decrement! :asked_count unless author_is_anonymous || direct
# rubocop:enable Rails/SkipsModelValidations
end
def can_be_removed?
return false if self.answers.count > 0
return false if Inbox.where(question: self).count > 1
true
end
def generated? = %w[justask retrospring_exporter].include?(author_identifier)
def anonymous? = author_is_anonymous && author_identifier.present?
def long? = content.length > SHORT_QUESTION_MAX_LENGTH
end