Fix preview card search
This commit is contained in:
parent
10ec03f28b
commit
8a329b67a5
|
@ -57,12 +57,13 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue