fix: search with status and author (#5152)
This commit is contained in:
@@ -58,6 +58,8 @@ class Article < ApplicationRecord
|
||||
|
||||
scope :search_by_category_slug, ->(category_slug) { where(categories: { slug: category_slug }) if category_slug.present? }
|
||||
scope :search_by_category_locale, ->(locale) { where(categories: { locale: locale }) if locale.present? }
|
||||
scope :search_by_author, ->(author_id) { where(author_id: author_id) if author_id.present? }
|
||||
scope :search_by_status, ->(status) { where(status: status) if status.present? }
|
||||
|
||||
# TODO: if text search slows down https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS
|
||||
pg_search_scope(
|
||||
@@ -77,7 +79,10 @@ class Article < ApplicationRecord
|
||||
def self.search(params)
|
||||
records = joins(
|
||||
:category
|
||||
).search_by_category_slug(params[:category_slug]).search_by_category_locale(params[:locale])
|
||||
).search_by_category_slug(
|
||||
params[:category_slug]
|
||||
).search_by_category_locale(params[:locale]).search_by_author(params[:author_id]).search_by_status(params[:status])
|
||||
|
||||
records = records.text_search(params[:query]) if params[:query].present?
|
||||
records.page(current_page(params))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user