Added link/PreviewCard search to search

• Added:
- link/PreviewCard search to search
This commit is contained in:
mgabdev
2020-10-31 18:10:59 -05:00
parent 60f75ed676
commit 7e673d4e7f
9 changed files with 47 additions and 4 deletions

View File

@@ -57,6 +57,14 @@ class PreviewCard < ApplicationRecord
end
class << self
def search_for(term, limit = 100, offset = 0)
pattern = '%' + sanitize_sql_like(term.strip) + '%'
PreviewCard.where(
"lower(title) LIKE lower('#{pattern}') OR lower(description) LIKE lower('#{pattern}') OR lower(url) LIKE lower('#{pattern}')"
).order('updated_at DESC').limit(limit).offset(offset)
end
private
def image_styles(f)

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Search < ActiveModelSerializers::Model
attributes :accounts, :statuses, :hashtags, :groups
attributes :accounts, :statuses, :hashtags, :groups, :links
end