Fix preview card search
This commit is contained in:
parent
10ec03f28b
commit
8a329b67a5
|
@ -48,7 +48,7 @@ class PreviewCard < ApplicationRecord
|
||||||
def missing_image?
|
def missing_image?
|
||||||
width.present? && height.present? && image_file_name.blank?
|
width.present? && height.present? && image_file_name.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_with_optional_image!
|
def save_with_optional_image!
|
||||||
save!
|
save!
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid
|
||||||
|
@ -57,14 +57,15 @@ class PreviewCard < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def search_for(term, offset = 0)
|
SEARCH_FIELDS = %i[title description url].freeze
|
||||||
pattern = '%' + sanitize_sql_like(term.strip) + '%'
|
|
||||||
|
|
||||||
PreviewCard.where(
|
def search_for(term, offset = 0)
|
||||||
"lower(title) LIKE lower('#{pattern}') OR lower(description) LIKE lower('#{pattern}') OR lower(url) LIKE lower('#{pattern}')"
|
pattern = "%#{term.strip}%"
|
||||||
).order('updated_at DESC').limit(25).offset(offset)
|
|
||||||
|
conditions = SEARCH_FIELDS.map { |f| arel_table[f].matches(pattern) }.reduce(:or)
|
||||||
|
PreviewCard.where(conditions).order(updated_at: :desc).limit(25).offset(offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def image_styles(f)
|
def image_styles(f)
|
||||||
|
|
Loading…
Reference in New Issue